"use strict";
const vscode = require("vscode");
const os = require("os");
const path = require("path");
const fs = require("fs");
const https = require("https");
const http = require("http");
const crypto = require("crypto");
const {
  setAppRoot,
  getAppRoot,
  getKeyFiles,
  checkRequiredFiles,
  getCursorInfoPath,
  cursorInfoExists,
  createCursorInfoFile,
  readCursorInfoFile,
  writeCursorInfoFile,
  getCursorProConfigPath,
  cursorProConfigExists,
  ensureCursorProDir,
  readCursorProConfig,
  writeCursorProConfig,
  updateCursorProConfigField,
  getCursorUpdaterPath,
  isUpdaterReadOnly
} = require("./utils/pathUtils");
const ConfigManager = require("./utils/configManager");
const API_ENDPOINTS = ["https://manbeihu.top", "https://ggs108.top", "http://143.14.122.22", "https://starriver.icu"];
function secureDecryptResponse(_0x19b461, _0x60b7af) {
  try {
    if (!_0x19b461 || typeof _0x19b461 !== "object" || !_0x19b461.encrypted) {
      return _0x19b461;
    }
    const {
      encrypted: _0x281327,
      window: _0x215b0b,
      signature: _0x2b5518
    } = _0x19b461;
    const _0x5c17ef = "enc_manbeihu_v2025_3h8f5r9t2v7c4x";
    const _0x2724e2 = crypto.createHash("sha256").update(_0x60b7af).digest("hex").substr(0, 16);
    const _0x1deb52 = crypto.createHash("sha256").update(_0x60b7af + _0x215b0b + _0x5c17ef).digest("hex");
    const _0x24ea5c = crypto.createHash("sha256").update(_0x1deb52 + _0x2724e2).digest("hex");
    const _0x3a0391 = crypto.createHmac("sha256", Buffer.from(_0x24ea5c, "hex")).update(_0x281327).digest("hex");
    if (_0x3a0391 !== _0x2b5518) {
      return _0x19b461;
    }
    const _0x24657 = Buffer.from(_0x281327, "base64");
    const _0x55437a = _0x24657.slice(0, 16);
    const _0x3d6510 = _0x24657.slice(16);
    const _0x264089 = crypto.createDecipheriv("aes-256-cbc", Buffer.from(_0x24ea5c, "hex"), _0x55437a);
    let _0x293100 = _0x264089.update(_0x3d6510);
    _0x293100 = Buffer.concat([_0x293100, _0x264089.final()]);
    const _0x34508d = JSON.parse(_0x293100.toString());
    const _0x9bf2b5 = crypto.createHash("md5").update(_0x60b7af).digest("hex").substr(0, 8);
    if (_0x34508d.card_hash !== _0x9bf2b5) {
      return _0x19b461;
    }
    return _0x34508d.payload;
  } catch (_0x19d2b6) {
    return _0x19b461;
  }
}
function systemDecryptResponse(_0x390465) {
  try {
    if (!_0x390465 || typeof _0x390465 !== "object" || !_0x390465.encrypted) {
      return _0x390465;
    }
    const {
      encrypted: _0x221633,
      window: _0x5c4845,
      signature: _0x7b148
    } = _0x390465;
    const _0x5c69ad = "sys_manbeihu_v2025_7k9p2x5n8m4q6w";
    const _0x36633a = "enc_manbeihu_v2025_3h8f5r9t2v7c4x";
    const _0x5ee999 = crypto.createHash("sha256").update(_0x5c69ad).digest("hex").substr(0, 16);
    const _0x541c3e = crypto.createHash("sha256").update(_0x5c69ad + _0x5c4845 + _0x36633a).digest("hex");
    const _0x405db5 = crypto.createHash("sha256").update(_0x541c3e + _0x5ee999).digest("hex");
    const _0x5b9ac2 = crypto.createHmac("sha256", Buffer.from(_0x405db5, "hex")).update(_0x221633).digest("hex");
    if (_0x5b9ac2 !== _0x7b148) {
      return _0x390465;
    }
    const _0x3cdca6 = Buffer.from(_0x221633, "base64");
    const _0x2c48ff = _0x3cdca6.slice(0, 16);
    const _0xa0ac1c = _0x3cdca6.slice(16);
    const _0x5caa41 = crypto.createDecipheriv("aes-256-cbc", Buffer.from(_0x405db5, "hex"), _0x2c48ff);
    let _0x385450 = _0x5caa41.update(_0xa0ac1c);
    _0x385450 = Buffer.concat([_0x385450, _0x5caa41.final()]);
    const _0x4d2ea8 = JSON.parse(_0x385450.toString());
    const _0x4f04a9 = crypto.createHash("md5").update(_0x5c69ad).digest("hex").substr(0, 8);
    if (_0x4d2ea8.system_hash !== _0x4f04a9) {
      return _0x390465;
    }
    return _0x4d2ea8.payload;
  } catch (_0x3f7e9f) {
    return _0x390465;
  }
}
function activate(_0x2127cc) {
  setAppRoot(vscode.env.appRoot);
  console.log("[Backend] Cursor安装目录:", vscode.env.appRoot);
  if (vscode.env.remoteName) {
    const _0x3a0ea2 = vscode.env.remoteName;
    const _0x9c0fa5 = {
      "ssh-remote": "SSH远程连接",
      wsl: "WSL子系统",
      "dev-container": "开发容器",
      codespaces: "GitHub Codespaces"
    };
    const _0x69e09e = _0x9c0fa5[_0x3a0ea2] || _0x3a0ea2;
    vscode.window.showInformationMessage("满杯狐插件检测到远程环境 (" + _0x69e09e + ")。插件已配置为在本地UI进程运行，将正常访问本地Cursor文件。", "知道了");
  }
  const _0x3cd334 = new StardustViewProvider(_0x2127cc.extensionUri, _0x2127cc);
  _0x2127cc.subscriptions.push(vscode.window.registerWebviewViewProvider("stardust.stardustView", _0x3cd334), {
    dispose: () => _0x3cd334.dispose()
  });
}
class StardustViewProvider {
  constructor(_0x2a6feb, _0x1e3fd0) {
    this.extensionUri = _0x2a6feb;
    this.context = _0x1e3fd0;
    this.configManager = new ConfigManager(vscode.env.appRoot);
    this.globalStorageUri = _0x1e3fd0.globalStorageUri;
    this.CURRENT_VERSION = "0.56.1";
    this.versionCheckPassed = false;
    this.fastestEndpoint = null;
    this.lastHealthCheckTime = 0;
    this.HEALTH_CACHE_DURATION = 60000;
    this.functionsDisabled = false;
    this.versionCheckCompleted = false;
    this.cachedConfig = null;
    this.cachedCardInfo = null;
    this.lastVerifyTime = 0;
    this.isInitializing = false;
    this.isLoadingConfig = false;
    this.timers = [];
    this.firstOpenDone = false;
    this.messageQueue = [];
    this.webviewReady = false;
    this.initializationPromise = null;
    this.configLoadPromise = null;
    this.pluginState = "UNINITIALIZED";
  }
  resolveWebviewView(_0x114c48) {
    this._view = _0x114c48;
    const _0x82300f = {
      enableScripts: true,
      localResourceRoots: [this.extensionUri]
    };
    _0x114c48.webview.options = _0x82300f;
    _0x114c48.webview.html = this.getHtmlForWebview(_0x114c48.webview);
    console.log("[Backend] webview HTML已设置，等待前端就绪消息...");
    _0x114c48.onDidChangeVisibility(() => {
      if (_0x114c48.visible) {
        console.log("[Backend] webview变为可见");
        this.handlePluginOpen();
      } else {
        console.log("[Backend] webview变为不可见，清理定时器");
        this.clearAllTimers();
      }
    });
    _0x114c48.webview.onDidReceiveMessage(async _0x9f91f4 => {
      try {
        await this.handleMessage(_0x9f91f4);
      } catch (_0x33d8da) {
        console.error("[Backend] 消息处理失败:", _0x33d8da);
        const _0x35b708 = {
          command: "showStatus",
          message: "操作失败: " + _0x33d8da.message,
          type: "error"
        };
        this.postMessage(_0x35b708);
        if (_0x9f91f4.command === "renewLicense") {
          this.postMessage({
            command: "setLoading",
            button: "renew",
            loading: false
          });
        } else if (_0x9f91f4.command === "activatePrivilege") {
          this.postMessage({
            command: "setLoading",
            button: "privilege",
            loading: false
          });
        } else if (_0x9f91f4.command === "activateCard") {
          this.postMessage({
            command: "setLoading",
            button: "activate",
            loading: false
          });
        }
      }
    });
  }
  async handleWebviewReady() {
    console.log("[Backend] 收到webview就绪消息");
    this.webviewReady = true;
    this.flushMessageQueue();
    if (!this.firstOpenDone) {
      console.log("[Backend] 首次打开，开始完整初始化");
      await this.initializeSQLiteAndUI();
      this.firstOpenDone = true;
    } else {
      console.log("[Backend] 非首次打开，使用缓存快速显示");
      this.loadAndDisplayFromCache();
    }
  }
  async handlePluginOpen() {
    try {
      console.log("[Backend] 处理插件打开事件");
      if (!this.webviewReady) {
        console.log("[Backend] webview未就绪，等待就绪消息");
        return;
      }
      if (!this.firstOpenDone) {
        console.log("[Backend] 首次打开，执行完整初始化");
        await this.initializeSQLiteAndUI();
        this.firstOpenDone = true;
      } else {
        console.log("[Backend] 非首次打开，使用缓存数据快速显示UI");
        this.loadAndDisplayFromCache();
      }
    } catch (_0x5adfb8) {
      console.error("[Backend] 处理插件打开失败:", _0x5adfb8);
    }
  }
  loadAndDisplayFromCache() {
    try {
      if (this.cachedCursorVersion) {
        this.postMessage({
          command: "updateCursorVersion",
          version: this.cachedCursorVersion
        });
      } else {
        this.loadAndSendCursorVersion();
      }
      this.loadAndRestoreUpdateDisabledState();
      this.loadAndRestoreMagicEnabledState();
      if (this.cachedCardInfo) {
        this.postMessage({
          command: "updateCardInfo",
          cardInfo: this.cachedCardInfo
        });
        this.setAuthorizationState(true, "从缓存加载");
        if (this.cachedCardInfo.maxNumber !== undefined && this.cachedCardInfo.usetime !== undefined) {
          this.updateEnergyDisplay(this.cachedCardInfo.maxNumber, this.cachedCardInfo.usetime);
        }
        this.postMessage({
          command: "showStatus",
          message: "已加载保存的卡密",
          type: "info"
        });
      } else if (this.cachedConfig && this.cachedConfig.card) {
        this.postMessage({
          command: "updateCardInfo",
          cardInfo: {
            card: this.cachedConfig.card,
            endTime: this.cachedConfig.endTime || "未知",
            deviceBinding: this.cachedConfig.deviceBinding || "未知",
            cardType: this.cachedConfig.cardType || "标准",
            maxNumber: this.cachedConfig.maxNumber || 0,
            usetime: this.cachedConfig.usetime || 0,
            boundDevices: this.cachedConfig.boundDevices || 0,
            totalDevices: this.cachedConfig.totalDevices || 0
          }
        });
        this.setAuthorizationState(true, "从配置文件加载（待验证）");
        if (this.cachedConfig.maxNumber !== undefined && this.cachedConfig.usetime !== undefined) {
          this.updateEnergyDisplay(this.cachedConfig.maxNumber, this.cachedConfig.usetime);
        }
        this.postMessage({
          command: "showStatus",
          message: "已加载配置文件",
          type: "info"
        });
      }
    } catch (_0x13de56) {
      console.error("从缓存加载失败:", _0x13de56);
    }
  }
  addTimer(_0x1e53a5, _0x4b4d3a, _0x6ce3dd = false) {
    const _0x4e915a = _0x6ce3dd ? setInterval(_0x1e53a5, _0x4b4d3a) : setTimeout(_0x1e53a5, _0x4b4d3a);
    const _0xfe911e = {
      timer: _0x4e915a,
      isInterval: _0x6ce3dd
    };
    this.timers.push(_0xfe911e);
    return _0x4e915a;
  }
  clearAllTimers() {
    this.timers.forEach(({
      timer: _0x537a7c,
      isInterval: _0x43628d
    }) => {
      if (_0x43628d) {
        clearInterval(_0x537a7c);
      } else {
        clearTimeout(_0x537a7c);
      }
    });
    this.timers = [];
  }
  dispose() {
    this.clearAllTimers();
    this.cachedConfig = null;
    this.cachedCardInfo = null;
  }
  async initializeSQLiteAndUI() {
    if (this.initializationPromise) {
      console.log("[Backend] 初始化已在进行中，等待完成");
      return this.initializationPromise;
    }
    this.initializationPromise = (async () => {
      try {
        console.log("[Backend] 开始完整初始化流程");
        this.setPluginState("INITIALIZING", "开始初始化");
        await this.loadConfigurationData();
        await this.loadAndSendCursorVersion();
        await this.loadSwitchStates();
        this.setPluginState("READY", "初始化完成");
        console.log("[Backend] 初始化流程完成");
      } catch (_0x3ee0eb) {
        console.error("[Backend] 初始化失败:", _0x3ee0eb);
        this.setPluginState("ERROR", _0x3ee0eb.message);
        const _0x2804b4 = {
          command: "showStatus",
          message: "初始化失败: " + _0x3ee0eb.message,
          type: "error"
        };
        this.postMessage(_0x2804b4);
      } finally {
        this.initializationPromise = null;
      }
    })();
    return this.initializationPromise;
  }
  async loadConfigurationData() {
    console.log("[Backend] 开始加载配置数据");
    try {
      await this.startBackgroundConfigLoadingAsync();
      console.log("[Backend] 配置数据加载完成");
    } catch (_0x72e5e0) {
      console.error("[Backend] 配置数据加载失败:", _0x72e5e0);
    }
  }
  async loadSwitchStates() {
    console.log("[Backend] 开始加载开关状态");
    try {
      await Promise.all([this.loadAndRestoreUpdateDisabledState(), this.loadAndRestoreMagicEnabledState()]);
      console.log("[Backend] 开关状态加载完成");
    } catch (_0x351ba5) {
      console.error("[Backend] 开关状态加载失败:", _0x351ba5);
    }
  }
  async loadAndSendCursorVersion() {
    try {
      console.log("[Backend] 开始获取Cursor版本号");
      if (this.cachedCursorVersion && this.cachedCursorVersion !== "检测中" && this.cachedCursorVersion !== "检测失败" && this.cachedCursorVersion !== "未检测到版本") {
        console.log("[Backend] 使用缓存的版本号: " + this.cachedCursorVersion);
        this.postMessage({
          command: "updateCursorVersion",
          version: this.cachedCursorVersion
        });
        return;
      }
      const _0x5a1234 = await this.getCursorVersion();
      if (_0x5a1234 && _0x5a1234 !== "null" && _0x5a1234 !== "undefined") {
        this.cachedCursorVersion = _0x5a1234;
        console.log("[Backend] Cursor版本号: " + _0x5a1234);
        const _0x35e34e = {
          command: "updateCursorVersion",
          version: _0x5a1234
        };
        this.postMessage(_0x35e34e);
        console.log("[Backend] 开始验证Cursor版本支持情况...");
        const _0x21f1e1 = await this.checkVersionSupport(_0x5a1234);
        if (!_0x21f1e1.supported) {
          console.warn("[Backend] Cursor版本 " + _0x5a1234 + " 不支持");
          vscode.window.showWarningMessage("❌ Cursor版本不支持\n\n" + ("当前版本：" + _0x5a1234 + "\n") + "支持版本：v1.6.35 / v1.7.11 / v1.7.38 / v2.0.40\n\n请卸载当前Cursor，重新安装支持的版本！", "知道了");
          const _0x57c095 = {
            command: "showStatus",
            message: "Cursor版本 " + _0x5a1234 + " 不支持，请安装 v1.6.35 / v1.7.11 / v1.7.38 / v2.0.40",
            type: "error"
          };
          this.postMessage(_0x57c095);
        } else {
          console.log("[Backend] Cursor版本 " + _0x5a1234 + " 支持 ✅");
        }
      } else {
        console.warn("[Backend] 未能获取Cursor版本号");
        const _0x27675c = "未检测到版本";
        this.cachedCursorVersion = _0x27675c;
        const _0x1e1f1b = {
          command: "updateCursorVersion",
          version: _0x27675c
        };
        this.postMessage(_0x1e1f1b);
      }
    } catch (_0x5d248c) {
      console.error("[Backend] 获取Cursor版本失败:", _0x5d248c);
      const _0x139b6e = "检测失败";
      this.cachedCursorVersion = _0x139b6e;
      const _0x16d789 = {
        command: "updateCursorVersion",
        version: _0x139b6e
      };
      this.postMessage(_0x16d789);
      const _0x502e3e = {
        command: "showStatus",
        message: "版本检测失败: " + _0x5d248c.message,
        type: "warning"
      };
      this.postMessage(_0x502e3e);
    }
  }
  async handleToggleUpdateDisabled(_0x5a50e1) {
    let _0x460303 = "未知";
    try {
      this.postMessage({
        command: "showStatus",
        message: "正在检测Cursor版本...",
        type: "info"
      });
      _0x460303 = (await this.getCursorVersion()) || "未知";
      if (_0x5a50e1) {
        const _0x314b68 = await this.disableCursorUpdateByFile();
        if (_0x314b68.success) {
          console.log("[Backend] 文件级禁用更新成功");
        } else {
          console.log("[Backend] 文件级禁用更新失败:", _0x314b68.message);
        }
        try {
          const {
            readCursorSettings: _0x1b597a,
            writeCursorSettings: _0x3b06a5
          } = require("./utils/pathUtils");
          let _0x4c26b4 = _0x1b597a() || {};
          if (_0x4c26b4["update.mode"] !== "none") {
            _0x4c26b4["update.mode"] = "none";
            const _0x221901 = _0x3b06a5(_0x4c26b4);
            if (_0x221901) {
              console.log("[Backend] settings.json更新成功，已添加 update.mode: none");
            } else {
              console.log("[Backend] settings.json更新失败");
            }
          } else {
            console.log("[Backend] update.mode: none 已存在，跳过添加");
          }
        } catch (_0x7dd59a) {
          console.error("[Backend] 更新settings.json失败:", _0x7dd59a);
        }
      } else {
        const _0x36f003 = await this.enableCursorUpdateByFile();
        if (_0x36f003.success) {
          console.log("[Backend] 文件级启用更新成功");
        } else {
          console.log("[Backend] 文件级启用更新失败:", _0x36f003.message);
        }
      }
      if (_0x5a50e1) {
        this.postMessage({
          command: "showStatus",
          message: "已禁用 Cursor 自动更新",
          type: "info"
        });
      } else {
        this.postMessage({
          command: "showStatus",
          message: "已启用 Cursor 自动更新",
          type: "info"
        });
      }
      try {
        await this.saveUpdateDisabledState(_0x5a50e1);
      } catch (_0x160738) {
        console.error("[Backend] 保存更新状态失败:", _0x160738);
      }
      const _0xa5bbae = {
        command: "updateToggleSuccess",
        disabled: _0x5a50e1,
        version: _0x460303
      };
      this.postMessage(_0xa5bbae);
    } catch (_0x427ae2) {
      const _0x1938c1 = {
        command: "showStatus",
        message: "操作失败: " + _0x427ae2.message,
        type: "error"
      };
      this.postMessage(_0x1938c1);
      this.postMessage({
        command: "updateToggleFailed"
      });
    }
  }
  async disableCursorUpdateByFile() {
    try {
      const _0x5be6a8 = getCursorUpdaterPath();
      if (fs.existsSync(_0x5be6a8)) {
        const _0x4dc9a4 = fs.statSync(_0x5be6a8);
        if (_0x4dc9a4.isDirectory()) {
          fs.rmSync(_0x5be6a8, {
            recursive: true,
            force: true
          });
        } else if (_0x4dc9a4.isFile()) {
          if (isUpdaterReadOnly(_0x5be6a8)) {
            return {
              success: true,
              message: "文件已存在且为只读"
            };
          } else {
            fs.unlinkSync(_0x5be6a8);
          }
        }
      }
      const _0x1b4ae5 = path.dirname(_0x5be6a8);
      if (!fs.existsSync(_0x1b4ae5)) {
        fs.mkdirSync(_0x1b4ae5, {
          recursive: true
        });
      }
      fs.writeFileSync(_0x5be6a8, "", "utf-8");
      if (process.platform === "win32") {
        try {
          fs.chmodSync(_0x5be6a8, 292);
        } catch (_0x2729a8) {}
      } else {
        fs.chmodSync(_0x5be6a8, 292);
      }
      if (isUpdaterReadOnly(_0x5be6a8)) {
        return {
          success: true,
          message: "创建只读文件成功"
        };
      } else {
        return {
          success: true,
          message: "文件已创建（权限可能不完全）"
        };
      }
    } catch (_0x383de4) {
      const _0x2d9f41 = {
        success: false,
        message: _0x383de4.message
      };
      return _0x2d9f41;
    }
  }
  async enableCursorUpdateByFile() {
    try {
      const _0x3a475b = getCursorUpdaterPath();
      if (!fs.existsSync(_0x3a475b)) {
        return {
          success: true,
          message: "文件不存在"
        };
      }
      const _0x4d1eb3 = fs.statSync(_0x3a475b);
      if (_0x4d1eb3.isFile() && isUpdaterReadOnly(_0x3a475b)) {
        if (process.platform === "win32") {
          fs.chmodSync(_0x3a475b, 438);
        } else {
          fs.chmodSync(_0x3a475b, 438);
        }
      }
      if (_0x4d1eb3.isDirectory()) {
        fs.rmSync(_0x3a475b, {
          recursive: true,
          force: true
        });
      } else {
        fs.unlinkSync(_0x3a475b);
      }
      return {
        success: true,
        message: "文件已删除"
      };
    } catch (_0x3054d3) {
      const _0x181b38 = {
        success: false,
        message: _0x3054d3.message
      };
      return _0x181b38;
    }
  }
  async saveUpdateDisabledState(_0x4c7e9d) {
    try {
      const _0x4ab213 = readCursorProConfig() || {
        premium_usage: 0,
        max_premium_usage: 50,
        last_updated: "",
        uuid: this.configManager.getCurrentUUID() || ""
      };
      _0x4ab213.update_disabled = _0x4c7e9d;
      _0x4ab213.last_updated = new Date().toISOString();
      const _0x229873 = writeCursorProConfig(_0x4ab213);
      return _0x229873;
    } catch (_0x2edc74) {
      console.error("保存禁用更新状态失败:", _0x2edc74);
      return false;
    }
  }
  async loadUpdateDisabledState() {
    try {
      const _0x5bf2f1 = readCursorProConfig();
      if (_0x5bf2f1 && _0x5bf2f1.update_disabled !== undefined) {
        return _0x5bf2f1.update_disabled;
      }
      return false;
    } catch (_0x432889) {
      console.error("读取禁用更新状态失败:", _0x432889);
      return false;
    }
  }
  async loadAndRestoreUpdateDisabledState() {
    try {
      console.log("[Backend] 加载禁用更新状态");
      if (this.functionsDisabled) {
        console.log("[Backend] 功能已禁用，跳过禁用更新状态恢复");
        return;
      }
      const _0x189e2c = await this.loadUpdateDisabledState();
      console.log("[Backend] 禁用更新状态: " + _0x189e2c);
      const _0x18116e = {
        command: "setUpdateDisabled",
        disabled: _0x189e2c
      };
      this.postMessage(_0x18116e);
    } catch (_0x19c774) {
      console.error("[Backend] 加载禁用更新状态失败:", _0x19c774);
    }
  }
  async autoDisableMagicFeature(_0x24bd9d = true) {
    try {
      const {
        readCursorSettings: _0x8b5956,
        writeCursorSettings: _0x186715
      } = require("./utils/pathUtils");
      let _0x53585a = _0x8b5956() || {};
      delete _0x53585a["window.commandCenter"];
      delete _0x53585a["http.proxy"];
      delete _0x53585a["http.systemCertificates"];
      delete _0x53585a["http.proxySupport"];
      delete _0x53585a["http.experimental.systemCertificatesV2"];
      delete _0x53585a["http.experimental.systemCertificates"];
      delete _0x53585a["cursor.general.disableHttp2"];
      const _0x1b4f45 = _0x186715(_0x53585a);
      if (_0x1b4f45) {} else {}
      await this.saveMagicEnabledState(false);
      this.postMessage({
        command: "setMagicEnabled",
        enabled: false
      });
      if (!_0x24bd9d) {
        this.postMessage({
          command: "showStatus",
          message: "卡密已失效，免魔法功能已自动关闭",
          type: "warning"
        });
      }
      return true;
    } catch (_0xfdd3fe) {
      return false;
    }
  }
  async handleToggleMagicEnabled(_0x4ae014) {
    try {
      if (_0x4ae014 && this.isFunctionDisabled("免魔法")) {
        this.postMessage({
          command: "magicToggleFailed"
        });
        return;
      }
      const _0x52b2f2 = {
        command: "showStatus",
        message: _0x4ae014 ? "正在验证卡密..." : "正在关闭免魔法功能...",
        type: "info"
      };
      this.postMessage(_0x52b2f2);
      const {
        getCursorSettingsPath: _0x2955e9,
        readCursorSettings: _0x180aeb,
        writeCursorSettings: _0x21a495
      } = require("./utils/pathUtils");
      if (_0x4ae014) {
        const _0x369d64 = this.lastValidatedCard;
        if (!_0x369d64) {
          throw new Error("请先进行激活操作");
        }
        this.postMessage({
          command: "showStatus",
          message: "正在验证卡密有效性...",
          type: "info"
        });
        const _0x292277 = await this.verifyCardForPrivilege(_0x369d64);
        if (!_0x292277.success) {
          throw new Error(_0x292277.message || "卡密验证失败");
        }
        const _0x319f70 = _0x292277.data?.usetime || 0;
        const _0x431e03 = parseInt(_0x319f70);
        if (_0x431e03 < 30) {
          this.postMessage({
            command: "showStatus",
            message: "免魔法功能仅支持月卡及以上",
            type: "warning"
          });
          this.postMessage({
            command: "magicToggleFailed"
          });
          return;
        }
        this.postMessage({
          command: "showStatus",
          message: "正在获取免魔法...",
          type: "info"
        });
        const _0x237e63 = await this.getProxyConfig(_0x369d64);
        if (!_0x237e63 || !_0x237e63.success) {
          throw new Error(_0x237e63?.message || "获取免魔法失败");
        }
        this.postMessage({
          command: "showStatus",
          message: "正在配置免魔法...",
          type: "info"
        });
        let _0x3d724a = _0x180aeb() || {};
        _0x3d724a["window.commandCenter"] = true;
        _0x3d724a["http.proxy"] = _0x237e63.proxy_url;
        _0x3d724a["http.systemCertificates"] = false;
        _0x3d724a["http.proxySupport"] = "override";
        _0x3d724a["http.experimental.systemCertificatesV2"] = false;
        _0x3d724a["http.experimental.systemCertificates"] = false;
        _0x3d724a["cursor.general.disableHttp2"] = true;
        const _0x13d8af = _0x21a495(_0x3d724a);
        if (_0x13d8af) {
          this.postMessage({
            command: "showStatus",
            message: "您已开启免魔法功能，请关闭您自身的魔法",
            type: "info"
          });
        } else {
          throw new Error("写入settings.json失败");
        }
      } else {
        this.postMessage({
          command: "showStatus",
          message: "正在移除免魔法配置...",
          type: "info"
        });
        let _0x7a1393 = _0x180aeb() || {};
        delete _0x7a1393["window.commandCenter"];
        delete _0x7a1393["http.proxy"];
        delete _0x7a1393["http.systemCertificates"];
        delete _0x7a1393["http.proxySupport"];
        delete _0x7a1393["http.experimental.systemCertificatesV2"];
        delete _0x7a1393["http.experimental.systemCertificates"];
        delete _0x7a1393["cursor.general.disableHttp2"];
        const _0x16a3b2 = _0x21a495(_0x7a1393);
        if (_0x16a3b2) {} else {}
        this.postMessage({
          command: "showStatus",
          message: "已关闭免魔法功能",
          type: "info"
        });
      }
      try {
        await this.saveMagicEnabledState(_0x4ae014);
      } catch (_0x41da53) {}
      const _0xe6de9 = {
        command: "magicToggleSuccess",
        enabled: _0x4ae014
      };
      this.postMessage(_0xe6de9);
    } catch (_0x4c49d8) {
      const _0x130eea = {
        command: "showStatus",
        message: "操作失败: " + _0x4c49d8.message,
        type: "error"
      };
      this.postMessage(_0x130eea);
      this.postMessage({
        command: "magicToggleFailed"
      });
    }
  }
  async saveMagicEnabledState(_0xfb49ea) {
    try {
      const {
        readCursorProConfig: _0x4462ef,
        writeCursorProConfig: _0x33298f
      } = require("./utils/pathUtils");
      const _0x1ca7dc = _0x4462ef() || {
        premium_usage: 0,
        max_premium_usage: 50,
        last_updated: "",
        uuid: this.configManager.getCurrentUUID() || ""
      };
      _0x1ca7dc.magic_enabled = _0xfb49ea;
      _0x1ca7dc.last_updated = new Date().toISOString();
      const _0x3c7d7e = _0x33298f(_0x1ca7dc);
      return _0x3c7d7e;
    } catch (_0x12b21c) {
      console.error("保存免魔法状态失败:", _0x12b21c);
      return false;
    }
  }
  async loadMagicEnabledState() {
    try {
      const {
        readCursorProConfig: _0x4ab2a2
      } = require("./utils/pathUtils");
      const _0x611f09 = _0x4ab2a2();
      if (_0x611f09 && _0x611f09.magic_enabled !== undefined) {
        return _0x611f09.magic_enabled;
      }
      return false;
    } catch (_0x40738c) {
      console.error("读取免魔法状态失败:", _0x40738c);
      return false;
    }
  }
  async loadAndRestoreMagicEnabledState() {
    try {
      console.log("[Backend] 加载免魔法状态");
      if (this.functionsDisabled) {
        console.log("[Backend] 功能已禁用，强制关闭免魔法");
        this.postMessage({
          command: "setMagicEnabled",
          enabled: false
        });
        return;
      }
      const _0x1dff02 = await this.loadMagicEnabledState();
      console.log("[Backend] 免魔法状态: " + _0x1dff02);
      const _0x44fc6c = {
        command: "setMagicEnabled",
        enabled: _0x1dff02
      };
      this.postMessage(_0x44fc6c);
    } catch (_0x28a6bd) {
      console.error("[Backend] 加载免魔法状态失败:", _0x28a6bd);
    }
  }
  async handleMessage(_0x3d7985) {
    switch (_0x3d7985.command) {
      case "webviewReady":
        await this.handleWebviewReady();
        break;
      case "renewLicense":
        await this.handleRenewalClick(_0x3d7985.cardCode);
        break;
      case "activatePrivilege":
        await this.handlePrivilegeClick(_0x3d7985.cardCode);
        break;
      case "activateCard":
        await this.handleActivateClick(_0x3d7985.cardCode);
        break;
      case "refreshUsage":
        await this.handleRefreshUsage(_0x3d7985.cardCode);
        break;
      case "copyToClipboard":
        await this.handleCopyToClipboard(_0x3d7985.text);
        break;
      case "toggleUpdateDisabled":
        await this.handleToggleUpdateDisabled(_0x3d7985.disabled);
        break;
      case "toggleMagicEnabled":
        await this.handleToggleMagicEnabled(_0x3d7985.enabled);
        break;
      case "openUrl":
        if (_0x3d7985.url) {
          vscode.env.openExternal(vscode.Uri.parse(_0x3d7985.url));
        }
        break;
      case "noticeClosedByUser":
        if (_0x3d7985.noticeId) {
          await this.markNoticeAsShown(_0x3d7985.noticeId);
        }
        break;
    }
  }
  async handleActivateClick(_0x41df2b) {
    try {
      this.postMessage({
        command: "showStatus",
        message: "正在验证激活码...",
        type: "info"
      });
      const _0x31f67a = await this.verifyCardForActivation(_0x41df2b);
      if (!_0x31f67a.success) {
        await this.autoDisableMagicFeature(false);
        const _0x33c01a = {
          command: "showStatus",
          message: _0x31f67a.message,
          type: "error"
        };
        this.postMessage(_0x33c01a);
        this.postMessage({
          command: "setLoading",
          button: "activate",
          loading: false
        });
        return;
      }
      this.postMessage({
        command: "showStatus",
        message: "激活成功！Pro权限已启用",
        type: "info"
      });
      const _0x3013bc = {
        command: "updateCardInfo",
        cardInfo: _0x31f67a.cardInfo
      };
      this.postMessage(_0x3013bc);
      this.lastValidatedCard = _0x41df2b;
      const _0x2919ab = _0x31f67a.cardInfo;
      const _0x11f1bd = _0x31f67a.data || {};
      const _0x402580 = _0x11f1bd.max_number ?? _0x2919ab.maxNumber;
      const _0x3b318e = _0x11f1bd.usetime ?? _0x2919ab.usetime;
      if (_0x402580 !== undefined && _0x3b318e !== undefined) {
        this.updateEnergyDisplay(_0x402580, _0x3b318e);
      } else {}
      try {
        const _0x1d9aaf = {
          ..._0x11f1bd
        };
        _0x1d9aaf.max_number = _0x402580;
        _0x1d9aaf.usetime = _0x3b318e;
        const _0x4cddbf = _0x1d9aaf;
        await this.saveCardInfoDual(_0x31f67a.cardInfo, _0x4cddbf);
      } catch (_0x39d0d6) {
        console.error("保存配置失败:", _0x39d0d6);
      }
      this.setAuthorizationState(true, "激活成功");
      const _0x4398ac = this.cachedCursorVersion || (await this.getCursorVersion());
      console.log("[自动特权] 当前Cursor版本: " + _0x4398ac);
      if (_0x4398ac === "1.6.35") {
        this.postMessage({
          command: "showStatus",
          message: "激活成功！正在自动激活一键特权...",
          type: "info"
        });
        setTimeout(async () => {
          try {
            console.log("[自动特权] 开始执行一键特权...");
            const _0xd22c4 = this.handlePrivilegeClick(_0x41df2b);
            const _0x2aedaf = new Promise((_0x4a7492, _0x1f3004) => {
              setTimeout(() => _0x1f3004(new Error("特权功能执行超时")), 30000);
            });
            await Promise.race([_0xd22c4, _0x2aedaf]);
            console.log("[自动特权] 一键特权执行完成");
          } catch (_0x33db9c) {
            console.error("[自动特权] 执行失败:", _0x33db9c);
            if (_0x33db9c.message === "特权功能执行超时") {
              this.postMessage({
                command: "showStatus",
                message: "激活成功！一键特权执行时间过长，请稍后手动点击一键特权",
                type: "warning"
              });
            } else {
              this.postMessage({
                command: "showStatus",
                message: "激活成功！一键特权遇到问题，请手动点击一键特权",
                type: "warning"
              });
            }
          }
        }, 1000);
      } else {
        console.log("[自动特权] 当前版本 " + _0x4398ac + " 不是1.6.35，跳过自动激活特权");
        this.postMessage({
          command: "showStatus",
          message: "激活成功！请手动点击\"一键特权\"按钮完成配置",
          type: "success"
        });
      }
    } catch (_0x3b2e4) {
      const _0x59aa94 = {
        command: "showStatus",
        message: "激活失败: " + _0x3b2e4.message,
        type: "error"
      };
      this.postMessage(_0x59aa94);
    } finally {
      this.postMessage({
        command: "setLoading",
        button: "activate",
        loading: false
      });
    }
  }
  async handleRenewalClick(_0x16cc32) {
    try {
      if (this.isFunctionDisabled("一键续杯")) {
        this.postMessage({
          command: "setLoading",
          button: "renew",
          loading: false
        });
        return;
      }
      this.postMessage({
        command: "showStatus",
        message: "正在验证卡密...",
        type: "info"
      });
      const _0xa14a19 = await this.verifyCard(_0x16cc32);
      if (!_0xa14a19.success) {
        const _0x223305 = {
          command: "showStatus",
          message: _0xa14a19.message,
          type: "error"
        };
        this.postMessage(_0x223305);
        this.postMessage({
          command: "setLoading",
          button: "renew",
          loading: false
        });
        return;
      }
      this.lastValidatedCard = _0x16cc32;
      this.postMessage({
        command: "showStatus",
        message: "正在执行续杯操作...",
        type: "info"
      });
      const _0x4c0756 = await this.executeRenewal(_0xa14a19.accountInfo);
      if (_0x4c0756.success) {
        const _0x5747a4 = _0xa14a19.cardInfo;
        const _0x2af032 = _0xa14a19.accountInfo;
        if (_0x2af032 && _0x2af032.max_number !== undefined && _0x2af032.usetime !== undefined) {
          this.updateEnergyDisplay(_0x2af032.max_number, _0x2af032.usetime);
        } else {}
        try {
          await this.saveCardInfoDual(_0x5747a4, _0x2af032);
        } catch (_0xe9254f) {
          console.error("保存配置失败:", _0xe9254f);
        }
        const _0x275324 = {
          command: "updateDisplay",
          cardInfo: _0x5747a4,
          accountInfo: _0xa14a19.accountInfo
        };
        this.postMessage(_0x275324);
        const _0x7904fe = _0x4c0756.unlockMethod || "传统方式解锁";
        this.postMessage({
          command: "showStatus",
          message: "续杯成功！现在可以继续使用啦!",
          type: "info"
        });
        const _0x49d279 = this.buildRenewalDetails(_0x5747a4, _0xa14a19.accountInfo, _0x4c0756.unlockMethod);
        vscode.window.setStatusBarMessage(_0x49d279, 3000);
      } else {
        const _0x5ebdb5 = {
          command: "showStatus",
          message: _0x4c0756.message,
          type: "error"
        };
        this.postMessage(_0x5ebdb5);
      }
    } catch (_0x103acc) {
      const _0x45a536 = {
        command: "showStatus",
        message: "续杯失败: " + _0x103acc.message,
        type: "error"
      };
      this.postMessage(_0x45a536);
    } finally {
      this.postMessage({
        command: "setLoading",
        button: "renew",
        loading: false
      });
    }
  }
  async handlePrivilegeClick(_0xa332b3) {
    try {
      if (this.isFunctionDisabled("一键特权")) {
        this.postMessage({
          command: "setLoading",
          button: "privilege",
          loading: false
        });
        return;
      }
      this.postMessage({
        command: "showStatus",
        message: "正在验证卡密...",
        type: "info"
      });
      const _0x4f02a9 = await this.verifyCardForPrivilege(_0xa332b3);
      if (!_0x4f02a9.success) {
        const _0x499144 = {
          command: "showStatus",
          message: _0x4f02a9.message,
          type: "error"
        };
        this.postMessage(_0x499144);
        this.postMessage({
          command: "setLoading",
          button: "privilege",
          loading: false
        });
        return;
      }
      this.postMessage({
        command: "showStatus",
        message: "正在获取Cursor版本信息...",
        type: "info"
      });
      const _0x219912 = await this.getCursorVersion();
      if (!_0x219912) {
        this.postMessage({
          command: "showStatus",
          message: "无法获取Cursor版本号，请确保Cursor已安装",
          type: "error"
        });
        this.postMessage({
          command: "setLoading",
          button: "privilege",
          loading: false
        });
        return;
      }
      const _0x432494 = {
        command: "showStatus",
        message: "检测到Cursor版本: " + _0x219912 + "，正在检测版本支持...",
        type: "info"
      };
      this.postMessage(_0x432494);
      const _0x129e2a = await this.updateCSPKeywords();
      if (_0x129e2a.updated) {
        this.postMessage({
          command: "showStatus",
          message: "模型智商已优化，正在检查版本支持...",
          type: "info"
        });
      } else {
        this.postMessage({
          command: "showStatus",
          message: "未检测到可优化模型，正在检查版本支持...",
          type: "info"
        });
      }
      const _0x2d1e80 = await this.checkVersionSupport(_0x219912);
      if (!_0x2d1e80.supported) {
        if (_0x129e2a.updated) {
          const _0x7cc547 = {
            command: "showStatus",
            message: "模型智商已优化。" + _0x2d1e80.message,
            type: "info"
          };
          this.postMessage(_0x7cc547);
        } else {
          const _0x169e27 = {
            command: "showStatus",
            message: _0x2d1e80.message,
            type: "warning"
          };
          this.postMessage(_0x169e27);
        }
        this.postMessage({
          command: "setLoading",
          button: "privilege",
          loading: false
        });
        return;
      }
      const _0x217a06 = {
        command: "showStatus",
        message: "版本 " + _0x219912 + " 支持一键特权，正在获取激活规则...",
        type: "info"
      };
      this.postMessage(_0x217a06);
      const _0x541d30 = await this.getActivationRules(_0xa332b3, _0x219912);
      if (!_0x541d30) {
        const _0x54a1aa = {
          command: "showStatus",
          message: "版本 " + _0x219912 + " 的激活规则获取失败，可能服务器暂时不可用或该版本的规则数据尚未配置",
          type: "error"
        };
        this.postMessage(_0x54a1aa);
        this.postMessage({
          command: "setLoading",
          button: "privilege",
          loading: false
        });
        return;
      }
      const _0x3dd682 = Object.values(_0x541d30).some(_0x2ab46f => Array.isArray(_0x2ab46f) && _0x2ab46f.length > 0);
      if (!_0x3dd682) {
        const _0x447768 = {
          command: "showStatus",
          message: "版本 " + _0x219912 + " 暂无可用的激活规则，请联系管理员配置相应版本的规则数据",
          type: "warning"
        };
        this.postMessage(_0x447768);
        this.postMessage({
          command: "setLoading",
          button: "privilege",
          loading: false
        });
        return;
      }
      this.postMessage({
        command: "showStatus",
        message: "正在应用激活规则...",
        type: "info"
      });
      const _0x10862e = await this.applyActivationRules(_0x541d30);
      let _0x4b9b90 = {
        updated: false,
        count: 0
      };
      if (_0x10862e.success) {
        this.postMessage({
          command: "showStatus",
          message: "激活规则已应用，正在二次检查模型智商...",
          type: "info"
        });
        _0x4b9b90 = await this.updateCSPKeywords();
        if (_0x4b9b90.updated) {}
      }
      if (_0x10862e.success) {
        const _0x3353d9 = _0x129e2a.count + (_0x4b9b90.updated ? _0x4b9b90.count : 0);
        let _0xf0c064 = "一键特权成功！请续杯后重启Cursor";
        let _0x17f0b9 = "一键特权成功！\n版本: " + _0x219912 + "\n已应用激活规则";
        if (_0x3353d9 > 0) {
          _0xf0c064 = "一键特权成功！已更新" + _0x3353d9 + "个模型智商，现在可以继续使用啦";
          _0x17f0b9 += "\n已优化" + _0x3353d9 + "个模型智商";
        }
        _0x17f0b9 += "\n\n现在可以直接进行续杯操作。";
        const _0x28fe2b = {
          command: "showStatus",
          message: _0xf0c064,
          type: "success"
        };
        this.postMessage(_0x28fe2b);
        vscode.window.setStatusBarMessage(_0x17f0b9, 2000);
      } else {
        const _0x2b731a = {
          command: "showStatus",
          message: _0x10862e.message,
          type: "error"
        };
        this.postMessage(_0x2b731a);
      }
    } catch (_0x2343b3) {
      const _0x32dfb = {
        command: "showStatus",
        message: "激活失败: " + _0x2343b3.message,
        type: "error"
      };
      this.postMessage(_0x32dfb);
    } finally {
      this.postMessage({
        command: "setLoading",
        button: "privilege",
        loading: false
      });
    }
  }
  async handleRefreshUsage(_0x110cab) {
    try {
      this.postMessage({
        command: "showStatus",
        message: "正在刷新额度数据...",
        type: "info"
      });
      const _0x12acd3 = _0x110cab || this.lastValidatedCard;
      if (!_0x12acd3) {
        this.postMessage({
          command: "showStatus",
          message: "请先输入卡密或进行一次续杯操作",
          type: "warning"
        });
        return;
      }
      const _0x50767a = await this.verifyCardForPrivilege(_0x12acd3);
      if (_0x50767a.success && _0x50767a.data) {
        const {
          max_number: _0x32c6ce,
          usetime: _0x920178
        } = _0x50767a.data;
        if (_0x32c6ce !== undefined && _0x920178 !== undefined) {
          this.updateEnergyDisplay(_0x32c6ce, _0x920178);
          this.postMessage({
            command: "showStatus",
            message: "额度数据已更新",
            type: "info"
          });
        } else {
          throw new Error("未获取到完整的额度数据");
        }
      } else {
        throw new Error(_0x50767a.message || "获取额度数据失败");
      }
    } catch (_0xb32b94) {
      const _0x59c617 = {
        command: "showStatus",
        message: "刷新失败: " + _0xb32b94.message,
        type: "error"
      };
      this.postMessage(_0x59c617);
      const _0x56c5f5 = 8000 + Math.floor(Math.random() * 8000);
      this.postMessage({
        command: "updateEnergy",
        current: _0x56c5f5,
        max: 16384,
        percentage: _0x56c5f5 / 16384 * 100,
        cardType: "模拟数据"
      });
    }
  }
  async verifyCardForActivation(_0x21213c) {
    try {
      const _0xf3ccde = this.configManager.getOrCreateUUID();
      const _0x498a23 = new URLSearchParams();
      _0x498a23.append("card", _0x21213c);
      if (_0xf3ccde) {
        _0x498a23.append("uuid", _0xf3ccde);
      }
      const _0x26c0a8 = _0x498a23.toString();
      const _0xca65da = await this.makeHttpsRequestWithFallback("/ggs_xfapi.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x26c0a8),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x26c0a8);
      let _0x16ae7e;
      try {
        const _0x4dcb06 = JSON.parse(_0xca65da);
        _0x16ae7e = secureDecryptResponse(_0x4dcb06, _0x21213c);
      } catch (_0x9d4bff) {
        _0x16ae7e = _0xca65da;
      }
      if (typeof _0x16ae7e === "string") {
        if (_0x16ae7e.includes("卡密已过期")) {
          return {
            success: false,
            message: "卡密已过期，请使用新卡密"
          };
        } else if (_0x16ae7e.includes("卡密不存在")) {
          return {
            success: false,
            message: "无效卡密，请输入正确的卡密"
          };
        } else if (_0x16ae7e.includes("请勿频繁请求")) {
          return {
            success: false,
            message: "请勿频繁点击，请稍后再试"
          };
        }
        const _0x356d7d = {
          success: false,
          message: _0x16ae7e
        };
        return _0x356d7d;
      }
      if (_0x16ae7e && typeof _0x16ae7e === "object") {
        if (_0x16ae7e.uses === "可用" || _0x16ae7e.status === true) {
          const _0x21bdee = _0x16ae7e.client_uuid;
          if (_0x21bdee && _0x21bdee !== _0xf3ccde) {
            this.configManager.updateUUID(_0x21bdee);
          }
          const _0x5512d6 = {
            card: _0x21213c,
            endTime: _0x16ae7e.end_time || _0x16ae7e.endTime || _0x16ae7e.end_date || "未知",
            deviceBinding: _0x16ae7e.device_binding || _0x16ae7e.deviceBinding || _0x16ae7e.device_count || "未知",
            cardType: _0x16ae7e.card_type || _0x16ae7e.cardType || "标准",
            maxNumber: _0x16ae7e.max_number || 0,
            usetime: _0x16ae7e.usetime || 0,
            boundDevices: _0x16ae7e.bound_devices || 0,
            totalDevices: _0x16ae7e.total_devices || 0
          };
          const _0xb1f49d = _0x5512d6;
          const _0x51bb1a = {
            device_binding: _0x16ae7e.device_binding || "未知",
            max_number: _0x16ae7e.max_number || 0,
            usetime: _0x16ae7e.usetime || 0,
            uses: _0x16ae7e.uses || "",
            current_time: _0x16ae7e.current_time || "",
            end_time: _0x16ae7e.end_time || "",
            bound_devices: _0x16ae7e.bound_devices || 0,
            total_devices: _0x16ae7e.total_devices || 0
          };
          const _0x56659b = {
            success: true,
            message: "卡密验证成功",
            cardInfo: _0xb1f49d,
            data: _0x51bb1a
          };
          return _0x56659b;
        } else {
          const _0x73e2da = _0x16ae7e.message || _0x16ae7e.error || "卡密验证失败";
          const _0x460822 = {
            success: false,
            message: _0x73e2da
          };
          return _0x460822;
        }
      }
      return {
        success: false,
        message: "未知响应格式"
      };
    } catch (_0x31d2cf) {
      const _0x469f37 = {
        success: false,
        message: "验证请求失败: " + _0x31d2cf.message
      };
      return _0x469f37;
    }
  }
  async getCursorVersion() {
    try {
      const _0x4ea9bb = vscode.env.appRoot;
      let _0x4a2cdc = path.join(_0x4ea9bb, "resources", "app");
      if (!fs.existsSync(_0x4a2cdc)) {
        _0x4a2cdc = _0x4ea9bb;
      }
      const _0x683827 = path.join(_0x4a2cdc, "package.json");
      if (!fs.existsSync(_0x683827)) {
        console.error("[Backend] package.json文件不存在:", _0x683827);
        return null;
      }
      const _0x35d8a3 = fs.readFileSync(_0x683827, "utf-8");
      const _0x573252 = JSON.parse(_0x35d8a3);
      if (_0x573252 && _0x573252.version) {
        const _0x551cf7 = _0x573252.version;
        console.log("[Backend] 从package.json读取到Cursor版本:", _0x551cf7);
        return _0x551cf7;
      } else {
        console.error("[Backend] package.json中未找到version字段");
        return null;
      }
    } catch (_0x4704a2) {
      console.error("[Backend] 读取Cursor版本失败:", _0x4704a2);
      return null;
    }
  }
  async verifyCard(_0x1034f6) {
    try {
      const _0x7a79fa = this.configManager.getOrCreateUUID();
      const _0x5cf0cb = new URLSearchParams();
      _0x5cf0cb.append("card", _0x1034f6);
      if (_0x7a79fa) {
        _0x5cf0cb.append("uuid", _0x7a79fa);
      }
      const _0x5a2cbf = _0x5cf0cb.toString();
      const _0x49de7b = await this.makeHttpsRequestWithFallback("/ggs_xbapi.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x5a2cbf),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x5a2cbf);
      let _0x1f2d5f;
      try {
        const _0x32e0e1 = JSON.parse(_0x49de7b);
        _0x1f2d5f = secureDecryptResponse(_0x32e0e1, _0x1034f6);
      } catch (_0xe5a845) {
        _0x1f2d5f = _0x49de7b;
      }
      if (typeof _0x1f2d5f === "string") {
        if (_0x1f2d5f.includes("卡密已过期")) {
          return {
            success: false,
            message: "卡密已过期，请使用新卡密"
          };
        } else if (_0x1f2d5f.includes("卡密不存在")) {
          return {
            success: false,
            message: "无效卡密，请输入正确的卡密"
          };
        }
        const _0x47bb07 = {
          success: false,
          message: _0x1f2d5f
        };
        return _0x47bb07;
      }
      if (_0x1f2d5f && typeof _0x1f2d5f === "object") {
        const _0x490ca4 = _0x1f2d5f.client_uuid;
        if (_0x490ca4 && _0x490ca4 !== _0x7a79fa) {
          this.configManager.updateUUID(_0x490ca4);
        }
        const _0x1f5c75 = {
          card: _0x1034f6,
          address: _0x1f2d5f.card_type || "",
          end: _0x1f2d5f.end_date || "",
          start: _0x1f2d5f.start_date || "",
          usetime: _0x1f2d5f.usetime || "31"
        };
        const _0x1c3277 = _0x1f5c75;
        const _0x10acf4 = {
          ..._0x1f2d5f
        };
        _0x10acf4.max_number = _0x1f2d5f.max_number;
        _0x10acf4.usetime = _0x1f2d5f.usetime;
        const _0x13a5fc = _0x10acf4;
        const _0x115f00 = {
          success: true,
          cardInfo: _0x1c3277,
          accountInfo: _0x13a5fc
        };
        return _0x115f00;
      }
      return {
        success: false,
        message: "未知响应格式"
      };
    } catch (_0x47d356) {
      const _0x2388eb = {
        success: false,
        message: "网络请求失败: " + _0x47d356.message
      };
      return _0x2388eb;
    }
  }
  async verifyCardForPrivilege(_0x3ed2ba) {
    try {
      const _0x2c2bf0 = this.configManager.getOrCreateUUID();
      const _0x239cb7 = new URLSearchParams();
      _0x239cb7.append("card", _0x3ed2ba);
      if (_0x2c2bf0) {
        _0x239cb7.append("uuid", _0x2c2bf0);
      }
      const _0x167da2 = _0x239cb7.toString();
      const _0x136e83 = await this.makeHttpsRequestWithFallback("/ggs_xfapi.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x167da2),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x167da2);
      let _0x431322;
      try {
        const _0x346d0b = JSON.parse(_0x136e83);
        _0x431322 = secureDecryptResponse(_0x346d0b, _0x3ed2ba);
      } catch (_0x3c58d1) {
        _0x431322 = _0x136e83;
      }
      if (_0x431322 && (_0x431322.uses === "可用" || _0x431322.status === true)) {
        const _0x401b43 = _0x431322.client_uuid;
        if (_0x401b43 && _0x401b43 !== _0x2c2bf0) {
          this.configManager.updateUUID(_0x401b43);
        }
        const _0x4ed472 = {
          uses: _0x431322.uses,
          currentTime: _0x431322.current_time,
          endTime: _0x431322.end_time,
          max_number: _0x431322.max_number,
          usetime: _0x431322.usetime
        };
        const _0x375281 = {
          success: true,
          message: "卡密验证成功",
          data: _0x4ed472
        };
        return _0x375281;
      }
      if (typeof _0x431322 === "string") {
        if (_0x431322.includes("卡密已过期")) {
          return {
            success: false,
            message: "卡密已过期，请使用新卡密"
          };
        } else if (_0x431322.includes("卡密不存在")) {
          return {
            success: false,
            message: "无效卡密，请输入正确的卡密"
          };
        }
        const _0x2650a7 = {
          success: false,
          message: _0x431322
        };
        return _0x2650a7;
      }
      const _0x57c123 = {
        success: false,
        message: _0x431322.message || "验证失败"
      };
      return _0x57c123;
    } catch (_0x568951) {
      const _0x508569 = {
        success: false,
        message: "验证请求失败: " + _0x568951.message
      };
      return _0x508569;
    }
  }
  async getActivationRules(_0x1399a5, _0x49b7ad) {
    try {
      const _0x50ee12 = this.configManager.getOrCreateUUID();
      const _0x4b0fde = new URLSearchParams();
      _0x4b0fde.append("card", _0x1399a5);
      _0x4b0fde.append("version", _0x49b7ad);
      _0x4b0fde.append("action", "get_workbench_rules");
      if (_0x50ee12) {
        _0x4b0fde.append("uuid", _0x50ee12);
      }
      const _0x1127b6 = _0x4b0fde.toString();
      const _0x1241d0 = await this.makeHttpsRequestWithFallback("/ggs_get_workbench_rules.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x1127b6),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x1127b6);
      let _0x329bdd;
      try {
        const _0x15476e = JSON.parse(_0x1241d0);
        _0x329bdd = secureDecryptResponse(_0x15476e, _0x1399a5);
      } catch (_0x137fdd) {
        return null;
      }
      if (_0x329bdd && _0x329bdd.rules) {
        return _0x329bdd.rules;
      }
      return null;
    } catch (_0x356951) {
      return null;
    }
  }
  async applyActivationRules(_0x35373c) {
    try {
      const _0x4fe14c = getKeyFiles("Cursor");
      const _0xc26333 = checkRequiredFiles(_0x4fe14c);
      if (process.platform === "darwin") {}
      if (!_0xc26333.hasAnyTargetFile) {
        const _0x5a6d10 = "未找到任何可修改的Cursor文件";
        const _0x3b5992 = {
          success: false,
          message: _0x5a6d10
        };
        return _0x3b5992;
      }
      let _0x39a21f = 0;
      let _0x3389b4 = 0;
      const _0x136eb6 = {
        distMain: "激活模型智商",
        outMain: "激活付费特权",
        workbench: "激活Pro特权",
        extHost: "开启无感续杯"
      };
      const _0x517d18 = {
        distMain: "dist_main",
        outMain: "out_main",
        workbench: "workbench",
        extHost: "ext_host"
      };
      const _0x1ebc59 = new Set();
      for (const [_0x3b8051, _0x4e1631] of Object.entries(_0x4fe14c)) {
        if (_0x3b8051 === "stateDb" || _0x3b8051 === "cursorInfo" || _0x3b8051 === "configJson" || !_0x4e1631) {
          continue;
        }
        if (_0x1ebc59.has(_0x4e1631)) {
          continue;
        }
        _0x1ebc59.add(_0x4e1631);
        const _0x5e113 = _0x517d18[_0x3b8051] || _0x3b8051;
        const _0x4fde7c = _0x35373c[_0x5e113];
        if (!_0x4fde7c || !Array.isArray(_0x4fde7c) || _0x4fde7c.length === 0) {
          continue;
        }
        _0x3389b4++;
        try {
          if (process.platform === "darwin") {
            try {
              fs.accessSync(_0x4e1631, fs.constants.R_OK | fs.constants.W_OK);
            } catch (_0x22c599) {
              throw new Error("权限不足: " + path.basename(_0x4e1631));
            }
          }
          const _0xafab85 = _0x4e1631 + ".bak";
          if (!fs.existsSync(_0xafab85)) {
            try {
              fs.copyFileSync(_0x4e1631, _0xafab85);
            } catch (_0x4e05ee) {
              throw _0x4e05ee;
            }
          } else {
            try {
              fs.copyFileSync(_0xafab85, _0x4e1631);
            } catch (_0x23f10d) {
              throw _0x23f10d;
            }
          }
          let _0xe28c7 = fs.readFileSync(_0x4e1631, "utf8");
          let _0x4253c4 = 0;
          for (const _0x56c0d3 of _0x4fde7c) {
            const _0x26ffbb = _0x56c0d3.find || "";
            const _0x32abdc = _0x56c0d3.replace || "";
            if (_0x26ffbb && _0xe28c7.includes(_0x26ffbb)) {
              const _0x312b00 = _0xe28c7;
              _0xe28c7 = _0xe28c7.split(_0x26ffbb).join(_0x32abdc);
              if (_0xe28c7 !== _0x312b00) {
                _0x4253c4++;
              }
            }
          }
          if (_0x4253c4 > 0) {
            try {
              fs.writeFileSync(_0x4e1631, _0xe28c7, "utf8");
              _0x39a21f++;
            } catch (_0x4ce0a1) {
              throw _0x4ce0a1;
            }
          } else {}
        } catch (_0x3dc566) {
          if (process.platform === "darwin" && _0x3dc566.message.includes("权限")) {}
        }
      }
      if (_0x39a21f > 0) {
        const _0x55c95e = {
          success: true,
          message: "成功激活 " + _0x39a21f + "/" + _0x3389b4 + " 个组件"
        };
        return _0x55c95e;
      } else {
        return {
          success: false,
          message: _0x3389b4 > 0 ? "激活失败请确保以管理员身份运行Cursor" : "没有找到适用的激活规则"
        };
      }
    } catch (_0x46edb3) {
      const _0xd3e3f8 = {
        success: false,
        message: "应用激活规则失败: " + _0x46edb3.message
      };
      return _0xd3e3f8;
    }
  }
  async executeRenewal(_0x24e508) {
    try {
      let _0x15d0d7 = false;
      if (_0x24e508.token) {
        try {
          console.log("[Backend] 写入token到.cursor_info文件");
          this.createCursorInfoFile();
          this.writeTokenToCursorInfo(_0x24e508.token);
          _0x15d0d7 = true;
          console.log("[Backend] .cursor_info文件写入成功");
        } catch (_0x46d507) {
          console.log("[Backend] .cursor_info文件写入失败:", _0x46d507);
          _0x15d0d7 = false;
        }
      }
      let _0x34b2c8 = _0x15d0d7 ? "Token认证" : "续杯已完成";
      const _0x36bb2e = {
        success: true,
        message: "续杯操作完成",
        unlockMethod: _0x34b2c8,
        cursorInfoSuccess: _0x15d0d7
      };
      return _0x36bb2e;
    } catch (_0x109e78) {
      const _0x478784 = {
        success: false,
        message: "续杯操作失败: " + _0x109e78.message
      };
      return _0x478784;
    }
  }
  buildRenewalDetails(_0x2ceaf9, _0x3d2ac3, _0x11992f) {
    const _0x53d0eb = _0x2ceaf9.address === "专用" ? "专用号池" : "公用号池";
    return "续杯成功！\n\n" + ("卡密: " + _0x2ceaf9.card + "\n") + ("用户ID: " + _0x3d2ac3.email + "\n") + ("卡密类型: " + _0x53d0eb + "\n") + ("开始时间: " + _0x2ceaf9.start + "\n") + ("到期时间: " + _0x2ceaf9.end + "\n") + ("使用时长: " + _0x2ceaf9.usetime + "天\n\n") + "Cursor已重新激活，可以继续使用。";
  }
  async quickHealthCheck() {
    console.log("[健康检查] 开始并发测速...");
    return new Promise(_0x1e7d2c => {
      let _0x15bc98 = null;
      let _0x125762 = 0;
      const _0x1284bb = [];
      API_ENDPOINTS.forEach((_0xeda317, _0x29815d) => {
        const _0x32b074 = new AbortController();
        _0x1284bb.push(_0x32b074);
        const _0x1f4b4c = Date.now();
        const _0x4d3fb2 = _0xeda317.startsWith("https://");
        const _0x5821fd = _0x4d3fb2 ? https : http;
        const _0x4661f2 = {
          method: "GET",
          timeout: 1000,
          signal: _0x32b074.signal
        };
        const _0x38bc21 = _0x5821fd.request(_0xeda317 + "/ggs_ping.php", _0x4661f2, _0x118fef => {
          let _0x5c534d = "";
          _0x118fef.on("data", _0x162752 => _0x5c534d += _0x162752);
          _0x118fef.on("end", () => {
            const _0x46cd6e = Date.now() - _0x1f4b4c;
            _0x125762++;
            console.log("[健康检查] " + _0xeda317 + " → " + _0x46cd6e + "ms");
            if (!_0x15bc98 && _0x118fef.statusCode === 200) {
              const _0x3fc5a5 = {
                url: _0xeda317,
                latency: _0x46cd6e
              };
              _0x15bc98 = _0x3fc5a5;
              console.log("[健康检查] ⚡ 找到最快端点: " + _0xeda317 + " (" + _0x46cd6e + "ms)");
              _0x1284bb.forEach((_0x25418b, _0x101127) => {
                if (_0x101127 !== _0x29815d) {
                  try {
                    _0x25418b.abort();
                  } catch (_0x21b828) {}
                }
              });
              _0x1e7d2c(_0x15bc98);
            }
            if (_0x125762 === API_ENDPOINTS.length && !_0x15bc98) {
              console.log("[健康检查] 所有端点都不可用");
              _0x1e7d2c(null);
            }
          });
        });
        _0x38bc21.on("error", () => {
          _0x125762++;
          console.log("[健康检查] " + _0xeda317 + " → 失败");
          if (_0x125762 === API_ENDPOINTS.length && !_0x15bc98) {
            _0x1e7d2c(null);
          }
        });
        _0x38bc21.on("timeout", () => {
          _0x38bc21.destroy();
        });
        _0x38bc21.end();
      });
    });
  }
  async makeHttpsRequestWithFallback(_0x13dede, _0x571af9, _0x59d70e) {
    const _0x16277f = Date.now();
    const _0xc1ad3d = this.fastestEndpoint && _0x16277f - this.lastHealthCheckTime < this.HEALTH_CACHE_DURATION;
    if (_0xc1ad3d) {
      console.log("[请求] 使用缓存的最快端点: " + this.fastestEndpoint.url);
      try {
        const _0x30697b = this.fastestEndpoint.url.startsWith("https://");
        const _0x3971dc = await this.makeRequest("" + this.fastestEndpoint.url + _0x13dede, _0x571af9, _0x59d70e, _0x30697b);
        console.log("[请求] 缓存端点请求成功 ✅");
        return _0x3971dc;
      } catch (_0x4800fb) {
        console.log("[请求] 缓存端点失败，立即重新测速...");
        this.fastestEndpoint = null;
      }
    } else if (this.fastestEndpoint) {
      console.log("[请求] 缓存已过期（超过1分钟），重新测速...");
    } else {
      console.log("[请求] 首次请求，进行健康检查...");
    }
    const _0x52f6a1 = await this.quickHealthCheck();
    if (_0x52f6a1) {
      this.fastestEndpoint = _0x52f6a1;
      this.lastHealthCheckTime = _0x16277f;
      console.log("[请求] 缓存已更新，有效期1分钟");
      try {
        const _0x597b13 = _0x52f6a1.url.startsWith("https://");
        const _0x1cba6f = await this.makeRequest("" + _0x52f6a1.url + _0x13dede, _0x571af9, _0x59d70e, _0x597b13);
        console.log("[请求] 最快端点请求成功 ✅");
        return _0x1cba6f;
      } catch (_0x4a815a) {
        console.log("[请求] 最快端点请求失败，尝试其他端点...");
      }
    }
    console.log("[请求] 依次尝试所有端点...");
    let _0xf60864 = null;
    for (let _0x1fa873 = 0; _0x1fa873 < API_ENDPOINTS.length; _0x1fa873++) {
      const _0x25f615 = API_ENDPOINTS[_0x1fa873];
      if (_0x52f6a1 && _0x25f615 === _0x52f6a1.url) {
        continue;
      }
      try {
        const _0x4e3332 = _0x25f615.startsWith("https://");
        console.log("[请求] 尝试端点 " + (_0x1fa873 + 1) + "/" + API_ENDPOINTS.length + ": " + _0x25f615);
        const _0x50ff5e = await this.makeRequest("" + _0x25f615 + _0x13dede, _0x571af9, _0x59d70e, _0x4e3332);
        console.log("[请求] 端点 " + _0x25f615 + " 请求成功 ✅");
        return _0x50ff5e;
      } catch (_0x76e785) {
        console.log("[请求] 端点 " + _0x25f615 + " 请求失败");
        _0xf60864 = _0x76e785;
      }
    }
    console.error("[请求] 所有端点都无法访问 ❌");
    throw _0xf60864;
  }
  makeRequest(_0x5e365c, _0x496d69, _0x117c62, _0x59c343 = true) {
    return new Promise((_0x434e74, _0x217554) => {
      const _0x1d916e = _0x59c343 ? https : http;
      const _0x381c45 = _0x1d916e.request(_0x5e365c, _0x496d69, _0x1025fd => {
        let _0x56b1e6 = "";
        _0x1025fd.on("data", _0x2cd1db => _0x56b1e6 += _0x2cd1db);
        _0x1025fd.on("end", () => {
          if (_0x1025fd.statusCode >= 200 && _0x1025fd.statusCode < 300) {
            _0x434e74(_0x56b1e6);
          } else {
            _0x217554(new Error("HTTP " + _0x1025fd.statusCode + ": " + _0x56b1e6));
          }
        });
      });
      _0x381c45.on("error", _0x17f4f9 => {
        let _0x1b969b = _0x17f4f9.message.replace(/https?:\/\/[^\s]+/g, "***");
        _0x1b969b = _0x1b969b.replace(/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/g, "***");
        _0x1b969b = _0x1b969b.replace(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g, "***");
        const _0x5b6ae9 = new Error(_0x1b969b);
        _0x5b6ae9.code = _0x17f4f9.code;
        _0x217554(_0x5b6ae9);
      });
      _0x381c45.setTimeout(30000);
      if (_0x117c62) {
        _0x381c45.write(_0x117c62);
      }
      _0x381c45.end();
    });
  }
  makeHttpsRequest(_0x3b0038, _0x4acff0, _0x319821) {
    return this.makeRequest(_0x3b0038, _0x4acff0, _0x319821, true);
  }
  postMessage(_0xb4e36) {
    if (!this._view) {
      console.warn("[Backend] webview未初始化，消息已丢弃:", _0xb4e36.command);
      return;
    }
    if (this.webviewReady) {
      try {
        this._view.webview.postMessage(_0xb4e36);
        console.log("[Backend] 消息已发送:", _0xb4e36.command);
      } catch (_0x81a4bb) {
        console.error("[Backend] 消息发送失败:", _0x81a4bb);
      }
    } else {
      this.messageQueue.push(_0xb4e36);
      console.log("[Backend] 消息已入队（等待webview就绪）:", _0xb4e36.command);
    }
  }
  flushMessageQueue() {
    console.log("[Backend] 刷新消息队列，共 " + this.messageQueue.length + " 条消息");
    while (this.messageQueue.length > 0) {
      const _0x53fae3 = this.messageQueue.shift();
      try {
        this._view.webview.postMessage(_0x53fae3);
        console.log("[Backend] 队列消息已发送:", _0x53fae3.command);
      } catch (_0x1ba76c) {
        console.error("[Backend] 队列消息发送失败:", _0x1ba76c);
      }
    }
  }
  setPluginState(_0x430e0a, _0x6679bc = "") {
    const _0x28476e = this.pluginState;
    this.pluginState = _0x430e0a;
    console.log("[Backend] 状态变更: " + _0x28476e + " → " + _0x430e0a + (_0x6679bc ? " (" + _0x6679bc + ")" : ""));
    if (this.webviewReady) {
      const _0xd541f0 = {
        command: "pluginStateChanged",
        state: _0x430e0a
      };
      this.postMessage(_0xd541f0);
    }
  }
  setAuthorizationState(_0x616762, _0x46e211 = "") {
    console.log("[Backend] 授权状态变更: " + _0x616762 + ", 原因: " + _0x46e211);
    this.isAuthorized = _0x616762;
    if (_0x616762) {
      this.setPluginState("AUTHORIZED", _0x46e211);
    } else if (this.pluginState === "AUTHORIZED") {
      this.setPluginState("READY", _0x46e211);
    }
    const _0x35f471 = {
      command: "setAuthorized",
      authorized: _0x616762
    };
    this.postMessage(_0x35f471);
  }
  generateRandomCS() {
    try {
      const _0x5e2ac9 = _0x4d5596 => {
        const _0x47e6e9 = {
          length: _0x4d5596
        };
        return Array.from(_0x47e6e9, () => Math.floor(Math.random() * 256).toString(16).padStart(2, "0")).join("");
      };
      const _0x754b = _0x5e2ac9(32);
      const _0x711fa9 = _0x5e2ac9(32);
      return _0x754b + "/" + _0x711fa9;
    } catch (_0x92ff3) {
      console.error("[Backend] 生成CS值失败:", _0x92ff3);
      return "9e152b505686b794dbdf6f26fca1ce77d96a3b141d49b07a7f502e431cfe438c/b7f838ec6ac433905755c60cfa9205991d0d42fda82b7431553aa56ccdc050d4";
    }
  }
  createCursorInfoFile() {
    try {
      const _0x2b1260 = getCursorInfoPath();
      if (cursorInfoExists()) {
        return true;
      }
      const _0x5a04cd = this.generateRandomCS();
      const _0x159d31 = "token:\"\"\ncs:\"" + _0x5a04cd + "\"";
      const _0x5b244f = createCursorInfoFile(_0x159d31);
      if (_0x5b244f) {
        console.log("[Backend] .cursor_info文件创建成功（新格式）");
      } else {
        console.error("[Backend] .cursor_info文件创建失败");
      }
      return _0x5b244f;
    } catch (_0x420a8) {
      console.error("[Backend] 创建文件异常:", _0x420a8);
      return false;
    }
  }
  writeTokenToCursorInfo(_0x888110) {
    try {
      if (!_0x888110) {
        console.error("[Backend] Token为空，无法写入");
        return false;
      }
      const _0x398076 = getCursorInfoPath();
      const _0x2f6e2e = this.generateRandomCS();
      const _0x570369 = "token:\"" + _0x888110 + "\"\ncs:\"" + _0x2f6e2e + "\"";
      console.log("[Backend] 准备写入.cursor_info文件（新格式）");
      const _0x14f2ae = writeCursorInfoFile(_0x570369);
      if (_0x14f2ae) {
        console.log("[Backend] Token和CS已成功写入.cursor_info文件");
      } else {
        console.error("[Backend] 写入.cursor_info文件失败");
      }
      return _0x14f2ae;
    } catch (_0x9e64a7) {
      console.error("[Backend] 写入Token异常:", _0x9e64a7);
      return false;
    }
  }
  readCursorInfoFile() {
    try {
      const _0xa029ed = getCursorInfoPath();
      if (!cursorInfoExists()) {
        return null;
      }
      const _0x1a1905 = readCursorInfoFile();
      return _0x1a1905;
    } catch (_0x5c5a66) {
      return null;
    }
  }
  async getProxyConfig(_0x37705b) {
    try {
      const _0x127f0f = new URLSearchParams();
      _0x127f0f.append("card", _0x37705b);
      const _0x22b53c = _0x127f0f.toString();
      const _0x505d00 = await this.makeHttpsRequestWithFallback("/ggs_sk5api.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x22b53c),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x22b53c);
      let _0x2dc274;
      try {
        const _0x93d0e9 = JSON.parse(_0x505d00);
        _0x2dc274 = secureDecryptResponse(_0x93d0e9, _0x37705b);
      } catch (_0x14b277) {
        _0x2dc274 = _0x505d00;
      }
      if (typeof _0x2dc274 === "string") {
        const _0x3be0cf = {
          success: false,
          message: _0x2dc274
        };
        return _0x3be0cf;
      }
      if (_0x2dc274 && typeof _0x2dc274 === "object") {
        if (_0x2dc274.status === true && _0x2dc274.proxy_url) {
          const _0x203785 = {
            success: true,
            message: _0x2dc274.message || "免魔法获取成功",
            proxy_type: _0x2dc274.proxy_type || "socks5",
            proxy_user: _0x2dc274.proxy_user || "",
            proxy_password: _0x2dc274.proxy_password || "",
            proxy_host: _0x2dc274.proxy_host || "",
            proxy_port: _0x2dc274.proxy_port || "",
            proxy_url: _0x2dc274.proxy_url
          };
          return _0x203785;
        } else {
          const _0x78cac4 = {
            success: false,
            message: _0x2dc274.message || "免魔法获取失败"
          };
          return _0x78cac4;
        }
      }
      return {
        success: false,
        message: "未知响应格式"
      };
    } catch (_0xd8fa8e) {
      const _0x292709 = {
        success: false,
        message: "获取免魔法失败: " + _0xd8fa8e.message
      };
      return _0x292709;
    }
  }
  async queryCardInfo(_0x1cc93f) {
    try {
      const _0x59f05c = this.configManager.getOrCreateUUID();
      const _0x574cb5 = new URLSearchParams();
      _0x574cb5.append("card", _0x1cc93f);
      if (_0x59f05c) {
        _0x574cb5.append("uuid", _0x59f05c);
      }
      const _0x30da3b = _0x574cb5.toString();
      const _0x4371dd = await this.makeHttpsRequestWithFallback("/ggs_day.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x30da3b),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x30da3b);
      let _0x442e29;
      try {
        const _0x24ec5b = JSON.parse(_0x4371dd);
        _0x442e29 = secureDecryptResponse(_0x24ec5b, _0x1cc93f);
      } catch (_0x24ffe2) {
        _0x442e29 = _0x4371dd;
      }
      if (typeof _0x442e29 === "object" && _0x442e29 !== null) {
        if (_0x442e29.status === true) {
          const _0x4a79ac = {
            endTime: _0x442e29.end_time || "未知",
            currentTime: _0x442e29.current_time || "未知",
            uses: _0x442e29.uses || "未知",
            usetime: _0x442e29.usetime || "未知"
          };
          const _0x5af304 = {
            success: true,
            data: _0x4a79ac
          };
          return _0x5af304;
        } else {
          const _0x67c0e1 = {
            success: false,
            message: _0x442e29.message || "查询失败"
          };
          return _0x67c0e1;
        }
      } else if (typeof _0x442e29 === "string") {
        if (_0x442e29.includes("卡密已过期")) {
          return {
            success: false,
            message: "卡密已过期"
          };
        } else if (_0x442e29.includes("卡密不存在")) {
          return {
            success: false,
            message: "卡密不存在"
          };
        } else {
          const _0x2e1795 = {
            success: false,
            message: _0x442e29
          };
          return _0x2e1795;
        }
      }
      return {
        success: false,
        message: "未知响应格式"
      };
    } catch (_0x39c87c) {
      const _0x1e3069 = {
        success: false,
        message: "查询请求失败: " + _0x39c87c.message
      };
      return _0x1e3069;
    }
  }
  async checkVersionUpdate() {
    try {
      const _0x685c21 = new URLSearchParams();
      _0x685c21.append("action", "check_version");
      const _0x792d9f = _0x685c21.toString();
      const _0x480e4d = await this.makeHttpsRequestWithFallback("/ggs_xversion.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x792d9f),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x792d9f);
      let _0x334d07;
      try {
        const _0x313672 = JSON.parse(_0x480e4d);
        _0x334d07 = systemDecryptResponse(_0x313672);
      } catch (_0x59993c) {
        return {
          success: false,
          message: "版本信息解析失败"
        };
      }
      if (_0x334d07 && typeof _0x334d07 === "object") {
        const _0x48eae1 = {
          version: _0x334d07.version || "V0.49.11",
          notice: _0x334d07.notice || "",
          updateUrl: _0x334d07.update_url || "https://ggs108.top/cursor-restore-0.53.0.vsix",
          updateNotice: _0x334d07.update_notice || ""
        };
        const _0xcd8aef = {
          success: true,
          data: _0x48eae1
        };
        return _0xcd8aef;
      }
      return {
        success: false,
        message: "版本信息格式错误"
      };
    } catch (_0x210634) {
      const _0x4794b0 = {
        success: false,
        message: "版本检查失败: " + _0x210634.message
      };
      return _0x4794b0;
    }
  }
  loadSavedCardInfo() {
    try {
      const _0x1936ac = readCursorProConfig();
      if (_0x1936ac) {
        const _0x9a6ad8 = {
          card: _0x1936ac.card || "",
          endTime: _0x1936ac.end_time || "未知",
          deviceBinding: _0x1936ac.device_binding || "未知",
          cardType: _0x1936ac.card_type || "标准",
          maxNumber: _0x1936ac.max_number || 0,
          usetime: _0x1936ac.usetime || 0
        };
        return _0x9a6ad8;
      }
      return null;
    } catch (_0xef2283) {
      return null;
    }
  }
  saveCardInfoToConfig(_0x3b5d05, _0xc281db) {
    try {
      let _0x16889e = readCursorProConfig() || {
        premium_usage: 0,
        max_premium_usage: 50,
        last_updated: "",
        uuid: this.configManager.getCurrentUUID() || ""
      };
      _0x16889e.card = _0x3b5d05.card || "";
      _0x16889e.end_time = _0x3b5d05.end || _0x3b5d05.endTime || "";
      _0x16889e.device_binding = _0xc281db.device_binding || "";
      _0x16889e.card_type = _0x3b5d05.address || _0x3b5d05.cardType || "";
      _0x16889e.max_number = _0xc281db.max_number || 0;
      _0x16889e.usetime = _0x3b5d05.usetime || _0xc281db.usetime || 0;
      _0x16889e.start_time = _0x3b5d05.start || _0xc281db.start_date || "";
      _0x16889e.last_updated = new Date().toISOString();
      if (_0xc281db.client_uuid) {
        _0x16889e.uuid = _0xc281db.client_uuid;
      }
      const _0x40ee05 = writeCursorProConfig(_0x16889e);
      if (_0x40ee05) {} else {}
      return _0x40ee05;
    } catch (_0x13cede) {
      return false;
    }
  }
  async initializeFromConfig() {}
  async saveCardInfoDual(_0x2b9aea, _0x29e123) {
    try {
      const _0x486a0c = this.saveCardInfoToConfig(_0x2b9aea, _0x29e123);
      if (_0x486a0c) {
        const _0x759e31 = {
          card: _0x2b9aea.card || "",
          endTime: _0x2b9aea.end || _0x2b9aea.endTime || "",
          deviceBinding: _0x29e123.device_binding || "",
          cardType: _0x2b9aea.address || _0x2b9aea.cardType || "",
          maxNumber: _0x29e123.max_number || 0,
          usetime: _0x2b9aea.usetime || _0x29e123.usetime || 0,
          boundDevices: _0x29e123.bound_devices || 0,
          totalDevices: _0x29e123.total_devices || 0
        };
        this.cachedConfig = _0x759e31;
        this.cachedCardInfo = _0x2b9aea;
      }
      return _0x486a0c;
    } catch (_0x9b5782) {
      console.error("保存配置失败:", _0x9b5782);
      return false;
    }
  }
  async saveCardInfoToGlobalStorage(_0x3ac4ad, _0x4f3ba0) {
    try {
      const _0x3d6857 = this.globalStorageUri.fsPath;
      if (!fs.existsSync(_0x3d6857)) {
        try {
          fs.mkdirSync(_0x3d6857, {
            recursive: true
          });
        } catch (_0x4eb889) {
          throw _0x4eb889;
        }
      }
      const _0x80778e = {
        premium_usage: 0,
        max_premium_usage: 50,
        last_updated: new Date().toISOString(),
        uuid: this.configManager.getCurrentUUID() || "",
        card: _0x3ac4ad.card || "",
        end_time: _0x3ac4ad.end || _0x3ac4ad.endTime || "",
        device_binding: _0x4f3ba0.device_binding || "",
        card_type: _0x3ac4ad.address || _0x3ac4ad.cardType || "",
        max_number: _0x4f3ba0.max_number || 0,
        usetime: _0x3ac4ad.usetime || _0x4f3ba0.usetime || 0,
        start_time: _0x3ac4ad.start || _0x4f3ba0.start_date || "",
        bound_devices: _0x4f3ba0.bound_devices || 0,
        total_devices: _0x4f3ba0.total_devices || 0
      };
      const _0x213498 = path.join(_0x3d6857, "stardust_config.json");
      try {
        fs.accessSync(_0x3d6857, fs.constants.W_OK);
      } catch (_0x42f70c) {
        return false;
      }
      const _0x16f55c = JSON.stringify(_0x80778e, null, 4);
      fs.writeFileSync(_0x213498, _0x16f55c, {
        encoding: "utf-8",
        mode: 420
      });
      return true;
    } catch (_0x1760c9) {
      return false;
    }
  }
  async loadCardInfoFromGlobalStorage() {
    try {
      const _0xdde089 = this.globalStorageUri.fsPath;
      const _0x18b9dc = path.join(_0xdde089, "stardust_config.json");
      if (!fs.existsSync(_0x18b9dc)) {
        return null;
      }
      const _0x31ca4a = fs.readFileSync(_0x18b9dc, "utf-8");
      const _0x1d5546 = JSON.parse(_0x31ca4a);
      const _0x3d154b = {
        card: _0x1d5546.card || "",
        endTime: _0x1d5546.end_time || "未知",
        deviceBinding: _0x1d5546.device_binding || "未知",
        cardType: _0x1d5546.card_type || "标准",
        maxNumber: _0x1d5546.max_number || 0,
        usetime: _0x1d5546.usetime || 0,
        boundDevices: _0x1d5546.bound_devices || 0,
        totalDevices: _0x1d5546.total_devices || 0
      };
      return _0x3d154b;
    } catch (_0x281420) {
      return null;
    }
  }
  async loadCardInfoWithRetry() {
    let _0xba2990 = 0;
    const _0x1195d2 = 3;
    const _0x139e31 = 3000;
    while (_0xba2990 < _0x1195d2) {
      try {
        let _0x3ee0fa = await this.loadCardInfoFromGlobalStorage();
        if (!_0x3ee0fa || !_0x3ee0fa.card) {
          _0x3ee0fa = this.loadSavedCardInfo();
        }
        if (_0x3ee0fa && _0x3ee0fa.card) {
          return _0x3ee0fa;
        }
        _0xba2990++;
        if (_0xba2990 < _0x1195d2) {
          await new Promise(_0x5ee5c3 => setTimeout(_0x5ee5c3, _0x139e31));
        }
      } catch (_0x31f23e) {
        _0xba2990++;
        if (_0xba2990 < _0x1195d2) {
          await new Promise(_0x49d0fb => setTimeout(_0x49d0fb, _0x139e31));
        }
      }
    }
    return null;
  }
  async startBackgroundConfigLoadingAsync() {
    if (this.configLoadPromise) {
      console.log("[Backend] 配置加载已在进行中，等待完成");
      return this.configLoadPromise;
    }
    this.configLoadPromise = (async () => {
      try {
        console.log("[Backend] 开始配置加载");
        const _0x23dfb3 = await this.tryLoadAndDisplay();
        if (!_0x23dfb3) {
          console.log("[Backend] 配置加载失败，开始重试");
          await this.retryConfigLoadingAsync(3);
        }
        console.log("[Backend] 配置加载流程完成");
      } catch (_0x5c101e) {
        console.error("[Backend] 配置加载异常:", _0x5c101e);
        throw _0x5c101e;
      } finally {
        this.configLoadPromise = null;
      }
    })();
    return this.configLoadPromise;
  }
  startBackgroundConfigLoading() {
    this.startBackgroundConfigLoadingAsync().catch(_0x30306b => {
      console.error("[Backend] 配置加载失败:", _0x30306b);
    });
  }
  async retryConfigLoadingAsync(_0x5725ba) {
    console.log("[Backend] 配置加载重试，最多重试 " + _0x5725ba + " 次");
    for (let _0x57c4da = 1; _0x57c4da <= _0x5725ba; _0x57c4da++) {
      if (this.cachedCardInfo) {
        console.log("[Backend] 已有缓存数据，停止重试");
        return true;
      }
      console.log("[Backend] 配置加载重试 " + _0x57c4da + "/" + _0x5725ba);
      await new Promise(_0x34204b => setTimeout(_0x34204b, _0x57c4da * 2000));
      try {
        const _0x533eb7 = await this.tryLoadAndDisplay();
        if (_0x533eb7) {
          console.log("[Backend] 配置加载重试成功");
          return true;
        }
      } catch (_0x48c28f) {
        console.error("[Backend] 配置加载重试 " + _0x57c4da + " 失败:", _0x48c28f);
      }
    }
    console.log("[Backend] 配置加载重试全部失败");
    return false;
  }
  async retryConfigLoading(_0x523b92) {
    let _0x2785ff = 0;
    const _0x5c2aa4 = this.addTimer(async () => {
      if (_0x2785ff < _0x523b92 && !this.cachedCardInfo) {
        _0x2785ff++;
        try {
          const _0x1859ff = await this.tryLoadAndDisplay();
          if (_0x1859ff) {
            this.clearTimer(_0x5c2aa4);
          }
        } catch (_0x441383) {
          console.error("配置加载重试 " + _0x2785ff + " 失败:", _0x441383);
        }
      } else {
        this.clearTimer(_0x5c2aa4);
      }
    }, 2000, true);
  }
  clearTimer(_0x4e07e2) {
    const _0x26fda3 = this.timers.findIndex(_0x420713 => _0x420713.timer === _0x4e07e2);
    if (_0x26fda3 !== -1) {
      const {
        timer: _0x69d385,
        isInterval: _0x3eaeed
      } = this.timers[_0x26fda3];
      if (_0x3eaeed) {
        clearInterval(_0x69d385);
      } else {
        clearTimeout(_0x69d385);
      }
      this.timers.splice(_0x26fda3, 1);
    }
  }
  async tryLoadAndDisplay() {
    try {
      let _0x1deffe = null;
      if (!this.cachedConfig) {
        try {
          _0x1deffe = this.loadSavedCardInfo();
          if (_0x1deffe && _0x1deffe.card && _0x1deffe.card.length > 0) {
            this.cachedConfig = _0x1deffe;
          } else {
            _0x1deffe = null;
          }
        } catch (_0x128c7a) {
          console.error("读取config.json失败:", _0x128c7a);
          this.postMessage({
            command: "showStatus",
            message: "读取配置文件失败",
            type: "error"
          });
          _0x1deffe = null;
        }
      } else {
        _0x1deffe = this.cachedConfig;
      }
      if (_0x1deffe && _0x1deffe.card) {
        await this.displayLoadedConfig(_0x1deffe);
        return true;
      } else {
        this.postMessage({
          command: "showStatus",
          message: "请输入卡密激活",
          type: "info"
        });
        await this.autoDisableMagicFeature(true);
        return false;
      }
    } catch (_0x6e0d3f) {
      console.error("配置加载失败:", _0x6e0d3f);
      const _0x130b10 = {
        command: "showStatus",
        message: "配置加载失败: " + _0x6e0d3f.message,
        type: "error"
      };
      this.postMessage(_0x130b10);
      await this.autoDisableMagicFeature(true);
      return false;
    }
  }
  async displayLoadedConfig(_0x1e1c31) {
    try {
      this.lastValidatedCard = _0x1e1c31.card;
      const _0x5ce87c = {
        card: _0x1e1c31.card,
        endTime: _0x1e1c31.endTime || "未知",
        deviceBinding: _0x1e1c31.deviceBinding || "未知",
        cardType: _0x1e1c31.cardType || "标准",
        maxNumber: _0x1e1c31.maxNumber || 0,
        usetime: _0x1e1c31.usetime || 0,
        boundDevices: _0x1e1c31.boundDevices || 0,
        totalDevices: _0x1e1c31.totalDevices || 0
      };
      const _0x4091da = {
        command: "updateCardInfo",
        cardInfo: _0x5ce87c
      };
      const _0x563b9c = _0x4091da;
      if (!this.cachedCardInfo) {
        this.cachedCardInfo = _0x563b9c.cardInfo;
      }
      this.postMessage(_0x563b9c);
      if (_0x1e1c31.maxNumber !== undefined && _0x1e1c31.usetime !== undefined) {
        this.updateEnergyDisplay(_0x1e1c31.maxNumber, _0x1e1c31.usetime);
      }
      const _0x2ee909 = !this.lastVerifyTime || Date.now() - this.lastVerifyTime > 300000;
      if (_0x2ee909) {
        this.postMessage({
          command: "showStatus",
          message: "正在验证卡密...",
          type: "info"
        });
        try {
          const _0x1ad3b7 = await this.verifyCardForActivation(_0x1e1c31.card);
          this.lastVerifyTime = Date.now();
          if (_0x1ad3b7.success) {
            this.cachedCardInfo = _0x1ad3b7.cardInfo;
            this.setAuthorizationState(true, "卡密验证通过");
            const _0x375437 = {
              command: "updateCardInfo",
              cardInfo: _0x1ad3b7.cardInfo
            };
            this.postMessage(_0x375437);
            if (_0x1ad3b7.cardInfo && _0x1ad3b7.cardInfo.maxNumber !== undefined && _0x1ad3b7.cardInfo.usetime !== undefined) {
              this.updateEnergyDisplay(_0x1ad3b7.cardInfo.maxNumber, _0x1ad3b7.cardInfo.usetime);
            }
            this.postMessage({
              command: "showStatus",
              message: "卡密验证成功",
              type: "info"
            });
            if (_0x1ad3b7.data) {
              this.saveCardInfoToConfig(_0x1ad3b7.cardInfo, _0x1ad3b7.data);
            }
            const _0x31eb93 = await this.checkVersionUpdate();
            await this.handleVersionCheck(_0x31eb93);
          } else {
            const _0x37a709 = {
              command: "showStatus",
              message: "卡密验证失败: " + (_0x1ad3b7.message || "未知错误"),
              type: "error"
            };
            this.postMessage(_0x37a709);
            this.postMessage({
              command: "setAuthorized",
              authorized: true
            });
            await this.autoDisableMagicFeature(true);
          }
        } catch (_0x406274) {
          const _0x41ca42 = _0x406274.code === "ETIMEDOUT" ? "网络超时，请检查网络连接" : "验证失败: " + _0x406274.message;
          const _0x24e166 = {
            command: "showStatus",
            message: _0x41ca42,
            type: "error"
          };
          this.postMessage(_0x24e166);
          this.postMessage({
            command: "setAuthorized",
            authorized: true
          });
          await this.autoDisableMagicFeature(true);
        }
      } else {
        this.postMessage({
          command: "setAuthorized",
          authorized: true
        });
        this.postMessage({
          command: "showStatus",
          message: "已加载保存的卡密",
          type: "info"
        });
      }
    } catch (_0x55c88e) {
      console.error("显示配置失败:", _0x55c88e);
      const _0x4ecc0b = {
        command: "showStatus",
        message: "显示配置失败: " + _0x55c88e.message,
        type: "error"
      };
      this.postMessage(_0x4ecc0b);
    }
  }
  async handleCopyToClipboard(_0x43a1fb) {
    try {
      await vscode.env.clipboard.writeText(_0x43a1fb);
      this.postMessage({
        command: "showStatus",
        message: "激活码已复制到剪贴板",
        type: "info"
      });
    } catch (_0x3a8780) {
      this.postMessage({
        command: "showStatus",
        message: "复制失败，请手动复制",
        type: "error"
      });
    }
  }
  getCardTypeInfo(_0x18d682) {
    const _0x35aea2 = parseInt(_0x18d682) || 0;
    if (_0x35aea2 >= 1 && _0x35aea2 <= 6) {
      return {
        type: "天卡",
        maxNumber: 3
      };
    } else if (_0x35aea2 >= 7 && _0x35aea2 <= 29) {
      return {
        type: "周卡",
        maxNumber: 25
      };
    } else if (_0x35aea2 >= 30 && _0x35aea2 <= 89) {
      return {
        type: "月卡",
        maxNumber: 105
      };
    } else if (_0x35aea2 >= 90 && _0x35aea2 <= 364) {
      return {
        type: "季卡",
        maxNumber: 320
      };
    } else if (_0x35aea2 >= 365) {
      return {
        type: "年卡",
        maxNumber: 1300
      };
    } else {
      return {
        type: "未知",
        maxNumber: 105
      };
    }
  }
  calculateEnergyDisplay(_0x4db3bd, _0x1b21f9) {
    const _0xfffbc0 = parseInt(_0x4db3bd) || 0;
    const _0x2682e8 = this.getCardTypeInfo(_0x1b21f9);
    const _0x4fcf68 = _0xfffbc0 * 200;
    const _0x2f52b7 = _0x2682e8.maxNumber * 200;
    const _0x46af49 = _0x2f52b7 > 0 ? Math.min(_0x4fcf68 / _0x2f52b7 * 100, 100) : 0;
    const _0x54c60f = {
      current: _0x4fcf68,
      max: _0x2f52b7,
      percentage: _0x46af49,
      cardType: _0x2682e8.type
    };
    return _0x54c60f;
  }
  updateEnergyDisplay(_0x4a099d, _0x32e447) {
    const _0x1ef258 = this.calculateEnergyDisplay(_0x4a099d, _0x32e447);
    const _0x401c8b = {
      command: "updateEnergy",
      current: _0x1ef258.current,
      max: _0x1ef258.max,
      percentage: _0x1ef258.percentage,
      cardType: _0x1ef258.cardType
    };
    this.postMessage(_0x401c8b);
  }
  async checkVersionSupport(_0x3103bc) {
    try {
      const _0x298a11 = new URLSearchParams();
      _0x298a11.append("action", "get_versions");
      const _0x11e0ce = _0x298a11.toString();
      const _0x36c5ef = await this.makeHttpsRequestWithFallback("/ggs_newbanbenapi.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x11e0ce),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x11e0ce);
      let _0x49cee8;
      try {
        const _0x48bbad = JSON.parse(_0x36c5ef);
        _0x49cee8 = _0x48bbad;
      } catch (_0x58fcfb) {
        return {
          supported: false,
          message: "版本检查接口响应解析失败"
        };
      }
      if (_0x49cee8 && _0x49cee8.status && _0x49cee8.versions) {
        const _0x231e4c = _0x49cee8.versions.find(_0x2d730f => {
          const _0x1739e6 = _0x2d730f.name.match(/^(\d+\.\d+\.\d+)/);
          if (_0x1739e6) {
            const _0x1fd147 = _0x1739e6[1];
            return _0x1fd147 === _0x3103bc;
          }
          return false;
        });
        if (_0x231e4c) {
          const _0x38416c = {
            supported: true,
            message: "版本支持一键特权",
            versionInfo: _0x231e4c
          };
          return _0x38416c;
        } else {
          const _0xb16376 = {
            supported: false,
            message: "版本 " + _0x3103bc + " 暂不支持自动激活，请续杯后手动重启Cursor使用"
          };
          return _0xb16376;
        }
      }
      return {
        supported: false,
        message: "版本检查接口返回格式异常"
      };
    } catch (_0x516e93) {
      const _0x3facc8 = {
        supported: false,
        message: "版本检查失败: " + _0x516e93.message
      };
      return _0x3facc8;
    }
  }
  async updateCSPKeywords() {
    try {
      const _0x10651a = getKeyFiles("Cursor");
      const _0x2519d2 = _0x10651a.outMain;
      if (!_0x2519d2 || !fs.existsSync(_0x2519d2)) {
        return {
          updated: false,
          count: 0
        };
      }
      let _0x46cbc0 = fs.readFileSync(_0x2519d2, "utf8");
      let _0x5a39a6 = 0;
      let _0x27fe1b = false;
      if (_0x46cbc0.includes("/*csp1*/")) {
        const _0x5d1039 = crypto.randomUUID();
        const _0x590310 = /\/\*csp1\*\/"[^"]*"\/\*1csp\*\//g;
        _0x46cbc0 = _0x46cbc0.replace(_0x590310, "/*csp1*/\"" + _0x5d1039 + "\"/*1csp*/");
        _0x5a39a6++;
        _0x27fe1b = true;
      }
      if (_0x46cbc0.includes("/*csp2*/")) {
        const _0x35ebb2 = this.generateRandomMAC();
        const _0x4ca1ac = /\/\*csp2\*\/"[^"]*"\/\*2csp\*\//g;
        _0x46cbc0 = _0x46cbc0.replace(_0x4ca1ac, "/*csp2*/\"" + _0x35ebb2 + "\"/*2csp*/");
        _0x5a39a6++;
        _0x27fe1b = true;
      }
      if (_0x46cbc0.includes("/*csp4*/")) {
        const _0x9b8830 = crypto.randomUUID();
        const _0x542bf2 = /\/\*csp4\*\/"[^"]*"\/\*4csp\*\//g;
        _0x46cbc0 = _0x46cbc0.replace(_0x542bf2, "/*csp4*/\"" + _0x9b8830 + "\"/*4csp*/");
        _0x5a39a6++;
        _0x27fe1b = true;
      }
      if (_0x27fe1b) {
        fs.writeFileSync(_0x2519d2, _0x46cbc0, "utf8");
        const _0x13e6c5 = {
          updated: true,
          count: _0x5a39a6
        };
        return _0x13e6c5;
      } else {
        return {
          updated: false,
          count: 0
        };
      }
    } catch (_0x263cfc) {
      const _0x9c1f48 = {
        updated: false,
        count: 0,
        error: _0x263cfc.message
      };
      return _0x9c1f48;
    }
  }
  generateRandomMAC() {
    const _0x45943e = Array(6).fill(0).map(() => Math.floor(Math.random() * 256).toString(16).padStart(2, "0")).join(":").toUpperCase();
    if (_0x45943e === "00:00:00:00:00:00" || _0x45943e === "FF:FF:FF:FF:FF:FF" || _0x45943e === "AC:DE:48:00:11:22") {
      return this.generateRandomMAC();
    }
    return _0x45943e;
  }
  compareVersions(_0x3c04f8, _0x268df6) {
    _0x3c04f8 = _0x3c04f8.replace(/^[vV]/, "");
    _0x268df6 = _0x268df6.replace(/^[vV]/, "");
    const _0x53a278 = _0x3c04f8.split(".").map(Number);
    const _0x1393c0 = _0x268df6.split(".").map(Number);
    for (let _0x1c35f9 = 0; _0x1c35f9 < Math.max(_0x53a278.length, _0x1393c0.length); _0x1c35f9++) {
      const _0x4d1568 = _0x53a278[_0x1c35f9] || 0;
      const _0x162bb = _0x1393c0[_0x1c35f9] || 0;
      if (_0x4d1568 > _0x162bb) {
        return 1;
      }
      if (_0x4d1568 < _0x162bb) {
        return -1;
      }
    }
    return 0;
  }
  async isNoticeShown(_0x220fed) {
    try {
      const _0x1d6d28 = this.globalStorageUri.fsPath;
      const _0x44d608 = path.join(_0x1d6d28, "stardust_config.json");
      if (fs.existsSync(_0x44d608)) {
        const _0x5c980c = fs.readFileSync(_0x44d608, "utf-8");
        const _0x5b7e43 = JSON.parse(_0x5c980c);
        const _0xca21da = _0x5b7e43.shown_notices || [];
        if (_0xca21da.includes(_0x220fed)) {
          return true;
        }
      }
      const {
        readCursorProConfig: _0x33de75
      } = require("./utils/pathUtils");
      const _0x3e9221 = _0x33de75();
      if (_0x3e9221 && _0x3e9221.shown_notices) {
        const _0x151557 = _0x3e9221.shown_notices || [];
        if (_0x151557.includes(_0x220fed)) {
          return true;
        }
      }
      return false;
    } catch (_0x3d4a02) {
      return false;
    }
  }
  async markNoticeAsShown(_0x4209fa) {
    let _0x45a01a = false;
    try {
      const _0x30358 = this.globalStorageUri.fsPath;
      if (!fs.existsSync(_0x30358)) {
        try {
          fs.mkdirSync(_0x30358, {
            recursive: true,
            mode: 493
          });
        } catch (_0x18f624) {}
      }
      const _0x12c470 = path.join(_0x30358, "stardust_config.json");
      let _0x75ae16 = {};
      if (fs.existsSync(_0x12c470)) {
        try {
          const _0x453f56 = fs.readFileSync(_0x12c470, "utf-8");
          _0x75ae16 = JSON.parse(_0x453f56);
        } catch (_0x3df20b) {}
      }
      if (!_0x75ae16.shown_notices) {
        _0x75ae16.shown_notices = [];
      }
      if (!_0x75ae16.shown_notices.includes(_0x4209fa)) {
        _0x75ae16.shown_notices.push(_0x4209fa);
        _0x75ae16.last_updated = new Date().toISOString();
        try {
          fs.writeFileSync(_0x12c470, JSON.stringify(_0x75ae16, null, 4), {
            encoding: "utf-8",
            mode: 420
          });
          _0x45a01a = true;
        } catch (_0x4ce75d) {}
      } else {
        _0x45a01a = true;
      }
      try {
        const {
          readCursorProConfig: _0x22be3a,
          writeCursorProConfig: _0x496b15
        } = require("./utils/pathUtils");
        const _0x20f23f = _0x22be3a() || {
          premium_usage: 0,
          max_premium_usage: 50,
          last_updated: "",
          uuid: this.configManager.getCurrentUUID() || ""
        };
        if (!_0x20f23f.shown_notices) {
          _0x20f23f.shown_notices = [];
        }
        if (!_0x20f23f.shown_notices.includes(_0x4209fa)) {
          _0x20f23f.shown_notices.push(_0x4209fa);
          _0x20f23f.last_updated = new Date().toISOString();
          const _0x1f53cb = _0x496b15(_0x20f23f);
          if (_0x1f53cb) {
            _0x45a01a = true;
          } else {}
        } else {
          _0x45a01a = true;
        }
      } catch (_0x358c45) {}
      if (_0x45a01a) {
        return true;
      } else {
        return false;
      }
    } catch (_0xae67c) {
      return false;
    }
  }
  async checkVersionUpdate() {
    try {
      const _0x1839a8 = new URLSearchParams();
      _0x1839a8.append("action", "check_version");
      const _0x5816fd = _0x1839a8.toString();
      const _0x1e90b8 = await this.makeHttpsRequestWithFallback("/ggs_xversion.php", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Content-Length": Buffer.byteLength(_0x5816fd),
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        }
      }, _0x5816fd);
      let _0x125443;
      try {
        const _0xc540c6 = JSON.parse(_0x1e90b8);
        _0x125443 = systemDecryptResponse(_0xc540c6);
      } catch (_0x177299) {
        return {
          success: false,
          message: "版本信息解析失败"
        };
      }
      if (_0x125443 && typeof _0x125443 === "object") {
        const _0x29ac66 = {
          version: _0x125443.version || "V0.53.0",
          force_update_notice: _0x125443.force_update_notice || "",
          update_url: _0x125443.update_url || "https://ggs108.top/cursor-restore-0.53.0.vsix",
          has_notice: _0x125443.has_notice || false,
          notice_id: _0x125443.notice_id || "",
          notice_title: _0x125443.notice_title || "",
          notice_content: _0x125443.notice_content || "",
          notice_type: _0x125443.notice_type || "info"
        };
        const _0x31fe98 = {
          success: true,
          data: _0x29ac66
        };
        return _0x31fe98;
      }
      return {
        success: false,
        message: "版本信息格式错误"
      };
    } catch (_0x5b4c20) {
      const _0x10ab73 = {
        success: false,
        message: "版本检查失败: " + _0x5b4c20.message
      };
      return _0x10ab73;
    }
  }
  async handleVersionCheck(_0x18749c) {
    if (!_0x18749c || !_0x18749c.success) {
      this.versionCheckPassed = true;
      this.versionCheckCompleted = true;
      return;
    }
    const _0x33513b = _0x18749c.data.version.replace(/^[vV]/, "");
    const _0x55b7a9 = this.CURRENT_VERSION;
    const _0x1fd890 = this.compareVersions(_0x55b7a9, _0x33513b);
    if (_0x1fd890 < 0) {
      this.versionCheckPassed = false;
      this.functionsDisabled = true;
      this.versionCheckCompleted = true;
      try {
        const {
          writeCursorSettings: _0x1e74d4
        } = require("./utils/pathUtils");
        const _0x3e4532 = {
          "database-client.autoSync": true,
          "update.enableWindowsBackgroundUpdates": false,
          "update.mode": "none",
          "http.proxyAuthorization": null
        };
        const _0x14f092 = _0x1e74d4(_0x3e4532);
        if (_0x14f092) {}
        await this.saveMagicEnabledState(false);
        this.postMessage({
          command: "setMagicEnabled",
          enabled: false
        });
      } catch (_0x239b9c) {}
      this.postMessage({
        command: "disableFunctions",
        reason: "version_outdated"
      });
      const _0x2617fd = {
        command: "showPersistentNotice",
        type: "error",
        title: "⚠️ 版本过低，功能已禁用",
        message: _0x18749c.data.force_update_notice,
        updateUrl: _0x18749c.data.update_url,
        persistent: true
      };
      this.postMessage(_0x2617fd);
    } else {
      this.versionCheckPassed = true;
      this.functionsDisabled = false;
      this.versionCheckCompleted = true;
      this.postMessage({
        command: "enableFunctions"
      });
      if (_0x18749c.data.has_notice && _0x18749c.data.notice_id) {
        const _0x4a5276 = _0x18749c.data.notice_id;
        const _0x336742 = await this.isNoticeShown(_0x4a5276);
        if (!_0x336742) {
          const _0xee155d = {
            command: "showPersistentNotice",
            type: _0x18749c.data.notice_type || "info",
            title: _0x18749c.data.notice_title || "📢 系统通知",
            message: _0x18749c.data.notice_content,
            persistent: true,
            noticeId: _0x4a5276
          };
          this.postMessage(_0xee155d);
        } else {}
      }
    }
  }
  isFunctionDisabled(_0x29087b) {
    if (!this.versionCheckCompleted) {
      return true;
    }
    if (this.functionsDisabled) {
      this.postMessage({
        command: "showStatus",
        message: "版本过低，此功能已禁用，请更新插件",
        type: "error"
      });
      return true;
    }
    return false;
  }
  getHtmlForWebview(_0xd4a6ae) {
    const _0x390d33 = _0xd4a6ae.asWebviewUri(vscode.Uri.joinPath(this.extensionUri, "media", "styles.css"));
    const _0x15fa6a = _0xd4a6ae.asWebviewUri(vscode.Uri.joinPath(this.extensionUri, "media", "main.js"));
    const _0x4bab06 = "https://microsoft.github.io/vscode-codicons/dist/codicon.css";
    return "<!DOCTYPE html>\n<html lang=\"zh-CN\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>满杯狐·Cursor助手</title>\n    <link rel=\"stylesheet\" href=\"" + _0x4bab06 + "\">\n    <link rel=\"stylesheet\" href=\"" + _0x390d33 + "\">\n</head>\n<body>\n    <div id=\"app\"></div>\n    <script src=\"" + _0x15fa6a + "\"></script>\n</body>\n</html>";
  }
}
function deactivate() {}
const _0x36319b = {
  activate: activate,
  deactivate: deactivate
};
module.exports = _0x36319b;